diff options
Diffstat (limited to 'day2/__init__.py')
| -rw-r--r-- | day2/__init__.py | 30 |
1 files changed, 10 insertions, 20 deletions
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 | |||
