blob: d7c995cbb621feba55992fd1c0b5c36e89c367b1 (
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
|
from abc import ABC
from itertools import groupby
from typing import Iterator, Any, List
from aoc import BaseAssignment
class Assignment(BaseAssignment, ABC):
def calculate_elf_calories(self, input: Iterator) -> List[int]:
return [
sum([
int(i)
for i
in group
])
for in_group, group
in groupby(input, key=bool)
if in_group
]
class AssignmentOne(Assignment):
example_result = 24000
def run(self, input: Iterator) -> int:
return max(self.calculate_elf_calories(input))
class AssignmentTwo(Assignment):
example_result = 45000
def run(self, input: Iterator) -> int:
return sum(
sorted(
self.calculate_elf_calories(input),
reverse=True
)[:3]
)
|