diff options
author | Marvin Borner | 2023-12-02 13:25:13 +0100 |
---|---|---|
committer | Marvin Borner | 2023-12-02 13:49:59 +0100 |
commit | edba9b050198227ff0f3ce02777206f0284958da (patch) | |
tree | ff337c3c0188eac5dba1116a61900a5bff74a1cb /2023/02 | |
parent | c0b0124c0ea30e812f968d5d3934e84f3c49a943 (diff) |
2in1
Diffstat (limited to '2023/02')
-rw-r--r-- | 2023/02/solve.py | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/2023/02/solve.py b/2023/02/solve.py index 3af1c01..59ddd08 100644 --- a/2023/02/solve.py +++ b/2023/02/solve.py @@ -12,31 +12,16 @@ def parse(l): return game, cube_sets -def part1(games): - res = 0 - for game in games: - valid = True - for cubes in game[1]: - if ( - (cubes[0] > 12 and cubes[1] == "red") - or (cubes[0] > 13 and cubes[1] == "green") - or (cubes[0] > 14 and cubes[1] == "blue") - ): - valid = False - if valid: - res += game[0] - print(res) - - -def part2(games): - res = 0 - for game in games: - red = max(c[0] for c in game[1] if c[1] == "red") - green = max(c[0] for c in game[1] if c[1] == "green") - blue = max(c[0] for c in game[1] if c[1] == "blue") - res += red * green * blue - print(res) - - -part1([parse(l) for l in L]) -part2([parse(l) for l in L]) +def solve(games): + part1 = 0 + part2 = 0 + for i, game in games: + red = max(c[0] for c in game if c[1] == "red") + green = max(c[0] for c in game if c[1] == "green") + blue = max(c[0] for c in game if c[1] == "blue") + part1 += 0 if red > 12 or green > 13 or blue > 14 else i + part2 += red * green * blue + print(part1, part2) + + +solve([parse(l) for l in L]) |