diff options
Diffstat (limited to 'day2')
| -rw-r--r-- | day2/__init__ (conflicted copy 2023-12-03 150713).py | 40 | ||||
| -rw-r--r-- | day2/__init__.py | 30 |
2 files changed, 10 insertions, 60 deletions
diff --git a/day2/__init__ (conflicted copy 2023-12-03 150713).py b/day2/__init__ (conflicted copy 2023-12-03 150713).py deleted file mode 100644 index 1191e0f..0000000 --- a/day2/__init__ (conflicted copy 2023-12-03 150713).py +++ /dev/null | |||
| @@ -1,40 +0,0 @@ | |||
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | from abc import ABC | ||
| 3 | from enum import Enum | ||
| 4 | from typing import Iterator | ||
| 5 | |||
| 6 | from aoc import BaseAssignment, I, T | ||
| 7 | |||
| 8 | |||
| 9 | class Color(Enum): | ||
| 10 | red = 'red' | ||
| 11 | green = 'green' | ||
| 12 | blue = 'blue' | ||
| 13 | |||
| 14 | ColorCount = tuple[int, Color] | ||
| 15 | |||
| 16 | class Assignment(BaseAssignment, ABC): | ||
| 17 | def parse_item(self, item: str) -> list[tuple[ColorCount, ...]]: | ||
| 18 | _, items = item.split(': ') | ||
| 19 | |||
| 20 | return [ | ||
| 21 | tuple( | ||
| 22 | tuple(( | ||
| 23 | int(_.split(' ')[0]), | ||
| 24 | Color(_.split(' ')[1]) | ||
| 25 | )) | ||
| 26 | for _ in pair.split(', ') | ||
| 27 | ) | ||
| 28 | for pair in items.split('; ') | ||
| 29 | ] | ||
| 30 | |||
| 31 | |||
| 32 | class AssignmentOne(Assignment): | ||
| 33 | example_result = 8 | ||
| 34 | def run(self, input: Iterator[I]) -> T: | ||
| 35 | for i in input: | ||
| 36 | print(i) | ||
| 37 | |||
| 38 | |||
| 39 | class AssignmentTwo(Assignment): | ||
| 40 | pass | ||
diff --git a/day2/__init__.py b/day2/__init__.py index 0afc441..c452878 100644 --- a/day2/__init__.py +++ b/day2/__init__.py | |||
| @@ -8,25 +8,24 @@ from aoc import BaseAssignment, I, T | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | class Color(Enum): | 10 | class Color(Enum): |
| 11 | red = 'red' | 11 | red = "red" |
| 12 | green = 'green' | 12 | green = "green" |
| 13 | blue = 'blue' | 13 | blue = "blue" |
| 14 | |||
| 14 | 15 | ||
| 15 | ColorCount = tuple[int, Color] | 16 | ColorCount = tuple[int, Color] |
| 16 | 17 | ||
| 18 | |||
| 17 | class Assignment(BaseAssignment, ABC): | 19 | class Assignment(BaseAssignment, ABC): |
| 18 | def parse_item(self, item: str) -> list[tuple[ColorCount, ...]]: | 20 | def parse_item(self, item: str) -> list[tuple[ColorCount, ...]]: |
| 19 | _, items = item.split(': ') | 21 | _, items = item.split(": ") |
| 20 | 22 | ||
| 21 | return [ | 23 | return [ |
| 22 | tuple( | 24 | tuple( |
| 23 | ColorCount(( | 25 | ColorCount((int(_.split(" ")[0]), Color(_.split(" ")[1]))) |
| 24 | int(_.split(' ')[0]), | 26 | for _ in pair.split(", ") |
| 25 | Color(_.split(' ')[1]) | ||
| 26 | )) | ||
| 27 | for _ in pair.split(', ') | ||
| 28 | ) | 27 | ) |
| 29 | for pair in items.split('; ') | 28 | for pair in items.split("; ") |
| 30 | ] | 29 | ] |
| 31 | 30 | ||
| 32 | 31 | ||
| @@ -75,15 +74,6 @@ class AssignmentTwo(Assignment): | |||
| 75 | 74 | ||
| 76 | for game in input: | 75 | for game in input: |
| 77 | counts = self.get_least_numbers(game) | 76 | counts = self.get_least_numbers(game) |
| 78 | powers.append( | 77 | powers.append(reduce(lambda total, item: total * item, counts.values(), 1)) |
| 79 | reduce( | ||
| 80 | lambda total, item: total * item, | ||
| 81 | counts.values(), | ||
| 82 | 1 | ||
| 83 | ) | ||
| 84 | ) | ||
| 85 | 78 | ||
| 86 | return sum(powers) | 79 | return sum(powers) |
| 87 | |||
| 88 | |||
| 89 | |||
