summaryrefslogtreecommitdiffstats
path: root/day6/__init__.py
blob: 616f055aaa8f508719fbed52d27851f3b22c0cdc (plain)
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
from collections import Counter
from copy import copy
from typing import List

from aoc import BaseAssignment


class Assignment(BaseAssignment):
    days = 80

    def parse_item(self, item: str) -> List[int]:
        return [ int(i) for i in item.split(',') ]

    def read_input(self, example = False) -> List[int]:
        return next(super().read_input(example))

    def run(self, input: List[int]) -> int:
        fish_counter = Counter(input)

        for _ in range(self.days):
            labour_fish = fish_counter.get(0, 0)

            for fish in range(8):
                fish_counter[fish] = fish_counter[fish + 1]

            fish_counter[6] += labour_fish
            fish_counter[8] = labour_fish

        return fish_counter.total()

class AssignmentOne(Assignment):
    example_result = 5934

class AssignmentTwo(Assignment):
    example_result = 26984457539
    days = 256