aocpy/2021/d6.py
2024-11-17 06:11:54 -05:00

33 lines
597 B
Python

from lib import get_data
from lib import ints
from collections import defaultdict
data = get_data(__file__).strip()
xs = ints(data)
for _ in range(80):
for i in range(len(xs)):
if xs[i] == 0:
xs[i] = 6
xs.append(8)
else:
xs[i] -= 1
print(len(xs))
xs = ints(data)
fish = defaultdict(int)
for x in xs:
fish[x] += 1
for _ in range(256):
new_fish = defaultdict(int)
new_fish[8] = fish[0]
new_fish[6] = fish[0]
for i in range(1, 9):
new_fish[i - 1] += fish[i]
fish = new_fish
r = sum(fish.values())
print(r)