diff --git a/6/6_2.py b/6/6_2.py new file mode 100755 index 0000000..6515cf0 --- /dev/null +++ b/6/6_2.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# 2021 - Advent Of Code - 6 part 2 + +def parse_file(file): + with open(file) as f: + line = f.readline() + + list_state = [int(x) for x in line.split(',')] + + state = dict(zip(range(0, 9), [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) + +lanternfish = 0 +for k, v in init_state.items(): + lanternfish += v + +print(f'There\'s {lanternfish} lanternfish after {DAYS} days')