Files
python-aoc-2020/day10/part2.py
2020-12-10 16:11:40 +01:00

34 lines
748 B
Python

import numpy as np
lines = sorted(int(x.strip()) for x in open("input.txt"))
lines.append(lines[-1]+3)
lines.insert(0, 0)
lines = np.array(lines)
diff = lines[1:] - lines[:-1]
one_count = 0
possibilities = 1
one_cache = [1]
def count_one_possibilities(one_cnt: int):
for idx in range(len(one_cache), one_cnt+1):
one_cache.append(sum(one_cache[-3:]))
return one_cache[one_cnt]
# only 3 and 1 differences are available
# 3 has to be taken / calculate possibilities for 1 hops
for num in diff:
if num == 1:
one_count += 1
elif num == 3:
possibilities *= count_one_possibilities(one_count)
one_count = 0
print(possibilities) # 64793042714624
print(one_cache) # {0: 1, 1: 1, 2: 2, 3: 4, 4: 7}