2019 day 16 complete
This commit is contained in:
37
2019/d16.py
37
2019/d16.py
@@ -40,7 +40,7 @@ def phase_with_offset(digits_in, pattern, offset):
|
|||||||
digits_out = digits_in.copy()
|
digits_out = digits_in.copy()
|
||||||
for round in range(offset, len(digits_in)):
|
for round in range(offset, len(digits_in)):
|
||||||
i, out = 0, 0
|
i, out = 0, 0
|
||||||
print(round)
|
# print(round)
|
||||||
|
|
||||||
pattern_value = pattern[((i + 1) // (round + 1)) % len(pattern)]
|
pattern_value = pattern[((i + 1) // (round + 1)) % len(pattern)]
|
||||||
if pattern_value == 0:
|
if pattern_value == 0:
|
||||||
@@ -53,8 +53,6 @@ def phase_with_offset(digits_in, pattern, offset):
|
|||||||
out += pattern_value * sum(
|
out += pattern_value * sum(
|
||||||
digits_in[i : min(i + 1 + round, len(digits_in))]
|
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
|
i += round + 1
|
||||||
|
|
||||||
out = abs(out) % 10
|
out = abs(out) % 10
|
||||||
@@ -71,16 +69,33 @@ def part_1(data):
|
|||||||
input = phase_with_offset(input, pattern, 0)
|
input = phase_with_offset(input, pattern, 0)
|
||||||
print("".join(map(str, input[:8])))
|
print("".join(map(str, input[:8])))
|
||||||
|
|
||||||
input = list(map(int, (data.strip()))) * 10_000
|
out = list(map(int, (data.strip()))) * 10_000
|
||||||
offset = int("".join(map(str, input[:7]))) - 200
|
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):
|
# digits = 40
|
||||||
print(i)
|
# for round in range(digits):
|
||||||
input = phase_with_offset(input, pattern, offset)
|
# s = ""
|
||||||
print(input)
|
# for i in range(digits):
|
||||||
|
# pattern_i = ((i + 1) // (round + 1)) % len(pattern)
|
||||||
return
|
# 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?
|
# What do I know?
|
||||||
#
|
#
|
||||||
# 1. There is a solution. Other people have solved it.
|
# 1. There is a solution. Other people have solved it.
|
||||||
|
|||||||
@@ -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 13: >120:00 (Just struggling so much for some reason.)
|
||||||
- Day 14: >120:00 (Hmm, wasn't that hard either.)
|
- Day 14: >120:00 (Hmm, wasn't that hard either.)
|
||||||
- Day 15: >120:00 (I am really weak at the moment.)
|
- 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 17: days (Fun but too tricky for me to be fast.)
|
||||||
- Day 18:
|
- Day 18:
|
||||||
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)
|
- Day 19: 40:00 (Way too slow! Oversight error. Come on.)
|
||||||
|
|||||||
Reference in New Issue
Block a user