You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
975 B
36 lines
975 B
import os
|
|
from collections import Counter
|
|
|
|
def tick(currentLanturnFish):
|
|
new_fish_to_spawn = 0
|
|
|
|
new_fish = Counter()
|
|
new_fish_to_spawn = currentLanturnFish['0']
|
|
new_fish['0'] = currentLanturnFish['1']
|
|
new_fish['1'] = currentLanturnFish['2']
|
|
new_fish['2'] = currentLanturnFish['3']
|
|
new_fish['3'] = currentLanturnFish['4']
|
|
new_fish['4'] = currentLanturnFish['5']
|
|
new_fish['5'] = currentLanturnFish['6']
|
|
new_fish['6'] = currentLanturnFish['7'] + new_fish_to_spawn
|
|
new_fish['7'] = currentLanturnFish['8']
|
|
new_fish['8'] = new_fish_to_spawn
|
|
|
|
return new_fish
|
|
|
|
dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
with open(os.path.join(dir, './input.txt'), 'r') as input_file:
|
|
|
|
lines = input_file.readlines()
|
|
|
|
line = lines[0].strip()
|
|
parts = line.split(',')
|
|
|
|
fish = Counter(parts)
|
|
print(fish)
|
|
|
|
days_to_predict = 256
|
|
for x in range(days_to_predict):
|
|
fish = tick(fish)
|
|
print(sum(fish.values()))
|