diff --git a/day06.py b/day06.py new file mode 100644 index 0000000..99211cd --- /dev/null +++ b/day06.py @@ -0,0 +1,31 @@ +from aoc import AOCDay +from typing import Any + + +def evolve_fishes(start_state: list[int], days: int) -> list[int]: + fishes = [0 for i in range(9)] + for x in start_state: + fishes[x] += 1 + + for day in range(days): + new_fishes = fishes[0] + for x in range(1, 9): + fishes[x - 1] = fishes[x] + + fishes[6] += new_fishes + fishes[8] = new_fishes + + return fishes + + +class Day(AOCDay): + test_solutions_p1 = [5934] + test_solutions_p2 = [26984457539] + + def part1(self) -> Any: + start_state = self.getInputAsArraySplit(",", int) + return sum(evolve_fishes(start_state, 80)) + + def part2(self) -> Any: + start_state = self.getInputAsArraySplit(",", int) + return sum(evolve_fishes(start_state, 256)) diff --git a/inputs/input06 b/inputs/input06 new file mode 100644 index 0000000..b800e1c --- /dev/null +++ b/inputs/input06 @@ -0,0 +1 @@ +1,5,5,1,5,1,5,3,1,3,2,4,3,4,1,1,3,5,4,4,2,1,2,1,2,1,2,1,5,2,1,5,1,2,2,1,5,5,5,1,1,1,5,1,3,4,5,1,2,2,5,5,3,4,5,4,4,1,4,5,3,4,4,5,2,4,2,2,1,3,4,3,2,3,4,1,4,4,4,5,1,3,4,2,5,4,5,3,1,4,1,1,1,2,4,2,1,5,1,4,5,3,3,4,1,1,4,3,4,1,1,1,5,4,3,5,2,4,1,1,2,3,2,4,4,3,3,5,3,1,4,5,5,4,3,3,5,1,5,3,5,2,5,1,5,5,2,3,3,1,1,2,2,4,3,1,5,1,1,3,1,4,1,2,3,5,5,1,2,3,4,3,4,1,1,5,5,3,3,4,5,1,1,4,1,4,1,3,5,5,1,4,3,1,3,5,5,5,5,5,2,2,1,2,4,1,5,3,3,5,4,5,4,1,5,1,5,1,2,5,4,5,5,3,2,2,2,5,4,4,3,3,1,4,1,2,3,1,5,4,5,3,4,1,1,2,2,1,2,5,1,1,1,5,4,5,2,1,4,4,1,1,3,3,1,3,2,1,5,2,3,4,5,3,5,4,3,1,3,5,5,5,5,2,1,1,4,2,5,1,5,1,3,4,3,5,5,1,4,3 diff --git a/inputs/test_input06_1_0 b/inputs/test_input06_1_0 new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/inputs/test_input06_1_0 @@ -0,0 +1 @@ +3,4,3,1,2 diff --git a/inputs/test_input06_2_0 b/inputs/test_input06_2_0 new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/inputs/test_input06_2_0 @@ -0,0 +1 @@ +3,4,3,1,2