diff --git a/6/6.py b/6/6.py new file mode 100755 index 0000000..bb8f882 --- /dev/null +++ b/6/6.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# 2021 - Advent Of Code - 6 + +def parse_file(file): + with open(file) as f: + line = f.readline() + return [int(x) for x in line.split(',')] + + +def iterate(state): + new_fish = 0 + for i in range(len(state)): + if state[i] == 0: + new_fish += 1 + state[i] = 6 + else: + state[i] -= 1 + state.extend([8]*new_fish) + + +init_state = parse_file('input.txt') +print(f'Initial state: {init_state}') + +DAYS = 80 + +for d in range(DAYS): + iterate(init_state) + # print(f'After {d+1:2} days: {init_state}') + +print(f'There\'s {len(init_state)} lanterfish after {DAYS} days') diff --git a/6/input.txt b/6/input.txt new file mode 100644 index 0000000..6b5d079 --- /dev/null +++ b/6/input.txt @@ -0,0 +1 @@ +3,5,3,1,4,4,5,5,2,1,4,3,5,1,3,5,3,2,4,3,5,3,1,1,2,1,4,5,3,1,4,5,4,3,3,4,3,1,1,2,2,4,1,1,4,3,4,4,2,4,3,1,5,1,2,3,2,4,4,1,1,1,3,3,5,1,4,5,5,2,5,3,3,1,1,2,3,3,3,1,4,1,5,1,5,3,3,1,5,3,4,3,1,4,1,1,1,2,1,2,3,2,2,4,3,5,5,4,5,3,1,4,4,2,4,4,5,1,5,3,3,5,5,4,4,1,3,2,3,1,2,4,5,3,3,5,4,1,1,5,2,5,1,5,5,4,1,1,1,1,5,3,3,4,4,2,2,1,5,1,1,1,4,4,2,2,2,2,2,5,5,2,4,4,4,1,2,5,4,5,2,5,4,3,1,1,5,4,5,3,2,3,4,1,4,1,1,3,5,1,2,5,1,1,1,5,1,1,4,2,3,4,1,3,3,2,3,1,1,4,4,3,2,1,2,1,4,2,5,4,2,5,3,2,3,3,4,1,3,5,5,1,3,4,5,1,1,3,1,2,1,1,1,1,5,1,1,2,1,4,5,2,1,5,4,2,2,5,5,1,5,1,2,1,5,2,4,3,2,3,1,1,1,2,3,1,4,3,1,2,3,2,1,3,3,2,1,2,5,2 diff --git a/6/input_example.txt b/6/input_example.txt new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/6/input_example.txt @@ -0,0 +1 @@ +3,4,3,1,2