From 7d30023c3378cc170723398e4c2658d57a8e1113 Mon Sep 17 00:00:00 2001 From: kwout Date: Sat, 2 Dec 2023 08:42:13 -0500 Subject: [PATCH] 2023 2a solved --- 2023/2.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2023/2.py diff --git a/2023/2.py b/2023/2.py new file mode 100644 index 0000000..f7f6a59 --- /dev/null +++ b/2023/2.py @@ -0,0 +1,16 @@ +lines = [i for i in open("input.txt", 'r').read().splitlines()] + +sum = 0 + +for l in lines: + sets = [[j.split(" ") for j in i.split(', ')] for i in l.split(": ")[1].split('; ')] + valid = True + for set in sets: + for cubes in set: + cubes[0] = int(cubes[0]) + if (cubes[1] == "red" and cubes[0] > 12) or (cubes[1] == "green" and cubes[0] > 13) or (cubes[1] == "blue" and cubes[0] > 14): + valid = False + if valid: + sum += int(l.split(": ")[0].split(" ")[1]) + +print(sum) \ No newline at end of file