blob: e6e4ac9c52a2809a2e662d10990cd6c7e6afd74a (
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
|
# -*- coding: utf-8 -*-
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])
|