summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/2/1.py
diff options
context:
space:
mode:
Diffstat (limited to 'prog/aoc/23/2/1.py')
-rwxr-xr-xprog/aoc/23/2/1.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/prog/aoc/23/2/1.py b/prog/aoc/23/2/1.py
new file mode 100755
index 0000000..db1ec3a
--- /dev/null
+++ b/prog/aoc/23/2/1.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python3
+def game_parser(line):
+ index = int(line.split(": ")[0].split(" ")[1])
+ pullouts = []
+ maxr = 0
+ maxg = 0
+ maxb = 0
+ for pullout in line.split(": ")[1].split("; "):
+ colordict = {}
+ for color in pullout.split(", "):
+ colordict[color.split(" ")[1]] = int(color.split(" ")[0])
+ r = 0
+ g = 0
+ b = 0
+ if "red" in colordict.keys():
+ r = colordict["red"]
+ if colordict["red"] > maxr:
+ maxr = colordict["red"]
+ if "green" in colordict.keys():
+ g = colordict["green"]
+ if colordict["green"] > maxg:
+ maxg = colordict["green"]
+ if "blue" in colordict.keys():
+ b = colordict["blue"]
+ if colordict["blue"] > maxb:
+ maxb = colordict["blue"]
+ pullouts.append((r, g, b))
+ return (index, (maxr, maxg, maxb), pullouts)
+sumindexes = 0
+sumpowers = 0
+try:
+ while True:
+ game = game_parser(input())
+ if game[1][0] <= 12 and game[1][1] <= 13 and game[1][2] <= 14:
+ sumindexes += game[0]
+ sumpowers += game[1][0] * game[1][1] * game[1][2]
+except EOFError:
+ print("1: " , sumindexes)
+ print("2: " , sumpowers)