-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ted Cassirer
committed
Dec 2, 2023
1 parent
a49d8c2
commit f6486d5
Showing
7 changed files
with
81 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import dataclasses | ||
from collections import defaultdict | ||
from typing import Self | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Round: | ||
id: int | ||
red: int = 0 | ||
blue: int = 0 | ||
green: int = 0 | ||
|
||
@classmethod | ||
def from_data_line(cls, line: str) -> Self: | ||
game_part, cube_part = line.split(": ") | ||
game_id = int(game_part.split(" ")[1]) | ||
|
||
most_seen: dict[str, int] = defaultdict(int) | ||
for cube_set in cube_part.split("; "): | ||
for draw in cube_set.split(", "): | ||
count, color = draw.split(" ") | ||
most_seen[color] = max(most_seen[color], int(count)) | ||
|
||
return Round(game_id, **most_seen) | ||
|
||
|
||
def part_a(data: str) -> int: | ||
result = 0 | ||
for round in map(Round.from_data_line, data.splitlines()): | ||
if round.red <= 12 and round.green <= 13 and round.blue <= 14: | ||
result += round.id | ||
return result | ||
|
||
|
||
def part_b(data: str) -> int: | ||
result = 0 | ||
for round in map(Round.from_data_line, data.splitlines()): | ||
result += round.blue * round.green * round.red | ||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
from aoc_cas.util import solve_with_examples | ||
|
||
solve_with_examples(year=2023, day=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
from aoc_cas.util import test_with_examples | ||
|
||
|
||
def part_a(data) -> int: | ||
def part_a(data: str) -> int: | ||
pass | ||
|
||
|
||
def part_b(data) -> int: | ||
def part_b(data: str) -> int: | ||
pass | ||
|
||
if __name__ == "__main__": | ||
test_with_examples({}, {}) | ||
from aoc_cas.util import solve_with_examples | ||
|
||
solve_with_examples(year={year}, day={day}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green | ||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue | ||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red | ||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red | ||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green | ||
8 | ||
2286 |