aoc/2021/06/06.py

30 lines
503 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(',')]
def advance(fish):
tomorrow = []
spawn = 0
for f in fish:
if f == 0:
tomorrow.append(6)
spawn += 1
else:
tomorrow.append(f-1)
for i in range(spawn):
tomorrow.append(8)
return tomorrow
def part1(fish):
for i in range(80):
fish = advance(fish)
return len(fish)
print(part1(fish))
## TOO LONG
# def part2(fish):
# for i in range(256):
# fish = advance(fish)
# return len(fish)
# print(part2(fish))