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.
 
 
 
adventofcode/2020/15.py

33 lines
627 B

#!/usr/bin/env python
from aoc import get_input # AoC
from collections import defaultdict as dd
nums = list(map( int, get_input(15).split(",")))
firstNums = dd(list)
for i, n in enumerate(nums):
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
#print(f"{num=} {i=} {nums=}")
firstNums[num].append(i)
return num
#maxturn = 2020
#maxturn = 30000000
maxturn = 10
print(numbers(maxturn))