aoc2021/6/a.py

39 lines
930 B
Python

with open("input.txt") as f:
pond = [int(i) for i in f.read().strip().split(",")]
print("pond", pond)
def simulate():
for i, fish in enumerate(pond[:]):
# print("i, fish", i, fish)
newfish = fish - 1
if newfish < 0:
newfish = 6
pond.append(8)
pond[i] = newfish
for i in range(0, 80):
# print("pond", len(pond))
simulate()
print("answer", len(pond))
# each lanternfish creates a new lanternfish once every 7 days.
# So, you can model each fish as a single number that represents the number of days until it creates a new lanternfish.
# a new lanternfish would surely need slightly longer before it's capable of producing more lanternfish: two more days for its first cycle.
# list of the ages of several hundred nearby lanternfish (your puzzle input).
# Find a way to simulate lanternfish. How many lanternfish would there be after 80 days?