#!/usr/bin/env python # 2021 - Advent Of Code - 6 part 2 def parse_file(file): with open(file, encoding="utf-8") as f: line = f.readline() list_state = [int(x) for x in line.split(',')] state = [0] * 9 for c in range(0, 9): state[c] = list_state.count(c) return state def iterate(state): new_fish = state[0] state[0] = state[1] state[1] = state[2] state[2] = state[3] state[3] = state[4] state[4] = state[5] state[5] = state[6] state[6] = state[7] + new_fish state[7] = state[8] state[8] = new_fish # init_state = parse_file('input_example.txt') init_state = parse_file('input.txt') print(f'Initial state: {init_state}') DAYS = 256 for d in range(DAYS): iterate(init_state) print(f'There\'s {sum(init_state)} lanternfish after {DAYS} days')