-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC2021_06.py
59 lines (42 loc) · 1.2 KB
/
AoC2021_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env python3
#
# Advent of Code 2021 Day 6
#
import sys
from collections import deque
from aoc.common import InputData
from aoc.common import SolutionBase
from aoc.common import aoc_samples
TEST = "3,4,3,1,2"
Input = list[int]
Output1 = int
Output2 = int
class Solution(SolutionBase[Input, Output1, Output2]):
def parse_input(self, input_data: InputData) -> Input:
return [int(_) for _ in list(input_data)[0].split(",")]
def solve(self, inputs: list[int], days: int) -> int:
fishies = deque([0] * 9)
for n in inputs:
fishies[n] += 1
for i in range(days):
zeroes = fishies[0]
fishies.rotate(-1)
fishies[6] += zeroes
return sum(fishies)
def part_1(self, inputs: Input) -> Output1:
return self.solve(inputs, days=80)
def part_2(self, inputs: Input) -> Output2:
return self.solve(inputs, days=256)
@aoc_samples(
(
("part_1", TEST, 5_934),
("part_2", TEST, 26_984_457_539),
)
)
def samples(self) -> None:
pass
solution = Solution(2021, 6)
def main() -> None:
solution.run(sys.argv)
if __name__ == "__main__":
main()