aoc2021/6/b.py
2021-12-05 21:24:16 -08:00

29 lines
540 B
Python

from collections import defaultdict
with open("input.txt") as f:
pond = [int(i) for i in f.read().strip().split(",")]
sea = defaultdict(lambda: 0)
for fish in pond:
sea[fish] += 1
for i in range(0, 256):
# print(i, dict(sea))
newsea = defaultdict(lambda: 0)
for fish, count in sea.items():
newfish = fish - 1
if newfish < 0:
newfish = 6
newsea[8] += count
newsea[newfish] += count
sea = newsea
# print(i, dict(sea))
# print()
print(sum(sea.values()))