My solutions for Advent of Code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
627 B

4 years ago
#!/usr/bin/env python
from aoc import get_input # AoC
4 years ago
from collections import defaultdict as dd
4 years ago
nums = list(map( int, get_input(15).split(",")))
4 years ago
firstNums = dd(list)
4 years ago
4 years ago
for i, n in enumerate(nums):
4 years ago
firstNums[n].append(i)
def numbers(maxt):
num = nums[-1]
for i in range(len(nums), maxt):
numsSeen = len(firstNums[num])
if( numsSeen > 1 ):
num = firstNums[num][-1] - firstNums[num][-2]
else:
num = 0
4 years ago
#print(f"{num=} {i=} {nums=}")
4 years ago
firstNums[num].append(i)
return num
#maxturn = 2020
4 years ago
#maxturn = 30000000
4 years ago
maxturn = 10
print(numbers(maxturn))