Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 16, 2019 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluepichu/bb1d4f9746bd4812caed8b6182eafd2d to your computer and use it in GitHub Desktop.
Save bluepichu/bb1d4f9746bd4812caed8b6182eafd2d to your computer and use it in GitHub Desktop.
Advent of Code 2019 day 16 solution
with open("input.txt") as f:
inp = list(map(int, f.read()[::]))
def do_phase(lst):
return [do_comp(lst, i) for i in range(len(lst))]
def get_mult(n, m):
m += 1
m %= 4 * n
if m < n:
return 0
elif m < 2 * n:
return 1
elif m < 3 * n:
return 0
elif m < 4 * n:
return -1
def do_comp(lst, idx):
idx += 1
out = 0
for i in range(len(lst)):
out += lst[i] * get_mult(idx, i)
return int(str(out)[-1:])
def do_phase2(inp):
s = sum(inp)
out = []
for i in range(len(inp)):
out += [((s % 10) + 10) % 10]
s -= inp[i]
return out
part_1 = inp[:]
for i in range(100):
part_1 = do_phase(part_1)
print("part 1:", "".join(map(str, part_1[:8])))
part_2 = inp[:]
offset = int("".join(map(str, part_2[:7])))
part_2 = part_2 * 10000
part_2 = part_2[offset:]
for i in range(100):
part_2 = do_phase2(part_2)
print("part 2:", "".join(map(str, part_2[:8])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment