From 754b022ae99ab356589a9440d11714bb5385e644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 3 Dec 2023 00:26:09 +0100 Subject: aoc2 --- prog/aoc/23/2/1.py | 39 +++++++++++++++++++++++++++++++++++++++ prog/aoc/23/2/in.txt | 5 +++++ 2 files changed, 44 insertions(+) create mode 100755 prog/aoc/23/2/1.py create mode 100644 prog/aoc/23/2/in.txt (limited to 'prog') 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) diff --git a/prog/aoc/23/2/in.txt b/prog/aoc/23/2/in.txt new file mode 100644 index 0000000..295c36d --- /dev/null +++ b/prog/aoc/23/2/in.txt @@ -0,0 +1,5 @@ +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 -- cgit v1.2.3