2019 day 16 complete

This commit is contained in:
felixm 2024-09-02 14:32:35 -04:00
parent 6cea472035
commit fa6ea1dfbe
2 changed files with 27 additions and 12 deletions

View File

@ -40,7 +40,7 @@ def phase_with_offset(digits_in, pattern, offset):
digits_out = digits_in.copy()
for round in range(offset, len(digits_in)):
i, out = 0, 0
print(round)
# print(round)
pattern_value = pattern[((i + 1) // (round + 1)) % len(pattern)]
if pattern_value == 0:
@ -53,8 +53,6 @@ def phase_with_offset(digits_in, pattern, offset):
out += pattern_value * sum(
digits_in[i : min(i + 1 + round, len(digits_in))]
)
# for j in range(i, min(i + 1 + round, len(digits_in))):
# out += (pattern_value * digits_in[j])
i += round + 1
out = abs(out) % 10
@ -71,16 +69,33 @@ def part_1(data):
input = phase_with_offset(input, pattern, 0)
print("".join(map(str, input[:8])))
input = list(map(int, (data.strip()))) * 10_000
offset = int("".join(map(str, input[:7]))) - 200
out = list(map(int, (data.strip()))) * 10_000
offset = int("".join(map(str, out[:7])))
for _ in range(100):
for i in range(len(out) - 2, len(out) - 1_000_000, -1):
out[i] = abs(out[i] + out[i + 1]) % 10
print("".join(map(str, out[offset : offset + 8])))
for i in range(100):
print(i)
input = phase_with_offset(input, pattern, offset)
print(input)
return
# digits = 40
# for round in range(digits):
# s = ""
# for i in range(digits):
# pattern_i = ((i + 1) // (round + 1)) % len(pattern)
# pattern_value = pattern[pattern_i]
# if pattern_value == 0:
# s += " "
# elif pattern_value == 1:
# s += "+"
# elif pattern_value == -1:
# s += "-"
# else:
# assert False
# print(s)
# return
# Just here to document my thought process. Mental hack: Assume that you
# have the capability to solve the problem easily.
#
# What do I know?
#
# 1. There is a solution. Other people have solved it.

View File

@ -127,7 +127,7 @@ Solutions and utility script for Advent of Code challenges in Python.
- Day 13: >120:00 (Just struggling so much for some reason.)
- Day 14: >120:00 (Hmm, wasn't that hard either.)
- Day 15: >120:00 (I am really weak at the moment.)
- Day 16:
- Day 16: days (Wow. Just too hard for me to solve quickly?)
- Day 17: days (Fun but too tricky for me to be fast.)
- Day 18:
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)