aoc/2021/06/06_refactored.py

21 lines
618 B
Python
Raw Normal View History

2021-12-07 02:54:30 +00:00
with open("sample.txt") as f:
fish = [int(n) for n in f.read().split(',')]
# note that we don't actually care about the timers themselves,
# we just care about the total count after x days.
#
# technically we also care about the timer values,
# since this directly influences the total count per daily cycle.
from collections import Counter
def advance(counter, days):
for day in range(days):
counter[(day+7)%9] += counter[day%9] # every 7 days, a new fish spawns taking 9 days.
return sum(counter.values())
c = Counter(fish)
part1 = advance(c,80)
c = Counter(fish)
part2 = advance(c,256)
print(part1, part2)