Advent-of-Code/2021/6/main2.py
2021-12-07 15:01:25 -05:00

36 lines
945 B
Python

# "constants":
total_fish = 0
# intialize shared data:
fish_reproducing_on_day = []
# functions:
def SimulateFishByDay(current_day):
fish_reproducing_on_day[current_day + 7] += fish_reproducing_on_day[current_day]
fish_reproducing_on_day[current_day + 9] += fish_reproducing_on_day[current_day]
return fish_reproducing_on_day[current_day]
def Simulate(days):
# reset data in case of multiple simulations:
fish_reproducing_on_day.clear()
for i in range(0, days + 9):
fish_reproducing_on_day.append(0)
for i in range(0, len(fish)):
fish_reproducing_on_day[int(fish[i])] += 1
grand_total = total_fish # starting fish count
for i in range(0, days):
grand_total += SimulateFishByDay(i)
return grand_total
#### MAIN EXECUTION ####
fish = []
with open('data', 'r') as fp:
fish = fp.readline().strip().split(',')
total_fish = len(fish)
print(Simulate(80))
print(Simulate(256))