diff options
| author | 2022-12-01 09:36:18 +0100 | |
|---|---|---|
| committer | 2022-12-01 09:36:18 +0100 | |
| commit | 469092002b7f1e1657468941bd86ccd3738baac3 (patch) | |
| tree | f61cbeefd0bb3e30944165caa6dc5302725f8966 /day1/__init__.py | |
| parent | f57d4d02c5b8050694784e948086271a7f4e49e5 (diff) | |
| download | 2022-469092002b7f1e1657468941bd86ccd3738baac3.tar.gz 2022-469092002b7f1e1657468941bd86ccd3738baac3.tar.bz2 2022-469092002b7f1e1657468941bd86ccd3738baac3.zip | |
Added pre-commit
Diffstat (limited to 'day1/__init__.py')
| -rw-r--r-- | day1/__init__.py | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/day1/__init__.py b/day1/__init__.py index d7c995c..e6e4ac9 100644 --- a/day1/__init__.py +++ b/day1/__init__.py | |||
| @@ -1,19 +1,16 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 1 | from abc import ABC | 2 | from abc import ABC |
| 2 | from itertools import groupby | 3 | from itertools import groupby |
| 3 | from typing import Iterator, Any, List | 4 | from typing import Iterator, Any, List |
| 4 | 5 | ||
| 5 | from aoc import BaseAssignment | 6 | from aoc import BaseAssignment |
| 6 | 7 | ||
| 8 | |||
| 7 | class Assignment(BaseAssignment, ABC): | 9 | class Assignment(BaseAssignment, ABC): |
| 8 | def calculate_elf_calories(self, input: Iterator) -> List[int]: | 10 | def calculate_elf_calories(self, input: Iterator) -> List[int]: |
| 9 | return [ | 11 | return [ |
| 10 | sum([ | 12 | sum([int(i) for i in group]) |
| 11 | int(i) | 13 | for in_group, group in groupby(input, key=bool) |
| 12 | for i | ||
| 13 | in group | ||
| 14 | ]) | ||
| 15 | for in_group, group | ||
| 16 | in groupby(input, key=bool) | ||
| 17 | if in_group | 14 | if in_group |
| 18 | ] | 15 | ] |
| 19 | 16 | ||
| @@ -29,11 +26,4 @@ class AssignmentTwo(Assignment): | |||
| 29 | example_result = 45000 | 26 | example_result = 45000 |
| 30 | 27 | ||
| 31 | def run(self, input: Iterator) -> int: | 28 | def run(self, input: Iterator) -> int: |
| 32 | return sum( | 29 | return sum(sorted(self.calculate_elf_calories(input), reverse=True)[:3]) |
| 33 | sorted( | ||
| 34 | self.calculate_elf_calories(input), | ||
| 35 | reverse=True | ||
| 36 | )[:3] | ||
| 37 | ) | ||
| 38 | |||
| 39 | |||
