diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-12-02 12:49:17 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-12-02 12:49:17 +0100 |
commit | 38b3c013883933a510580b7188a61e1f8d5757ef (patch) | |
tree | 3746eefc5127db01fd55ffa7398b0a109b064ad2 | |
parent | 88f3954385b272d74fac09b57544cd9ab3490668 (diff) |
day two part one
-rwxr-xr-x | 02/main.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/02/main.py b/02/main.py new file mode 100755 index 0000000..59f722b --- /dev/null +++ b/02/main.py @@ -0,0 +1,32 @@ +#!/bin/python3 +import sys +import re + +id_sum = 0 +for line in sys.stdin: + line = line.strip() + game_id, sets = line.split(":") + game_id = int(re.sub("[^0-9]", "", game_id)) + sets = [x.strip() for x in sets.split(";")] + possible = True + for set in sets: + cubes = [x.strip() for x in set.split(",")] + cubes = [{"color": x.split()[1], "count": int(x.split()[0])} for x in cubes] + map = { + "red": 0, + "green": 0, + "blue": 0, + } + for cube in cubes: + map[cube["color"]] = cube["count"] + + if map["red"] > 12 or map["green"] > 13 or map["blue"] > 14: + possible = False + break + if not possible: + continue + + id_sum += game_id + +print(f">> {id_sum}") + |