From fe205e12a9716e838ab65cb9957c74995180e438 Mon Sep 17 00:00:00 2001 From: Donald Date: Sat, 2 Dec 2023 07:17:55 +0000 Subject: [PATCH] part 1 working, class for each game and method to determine if game was possible or not. --- day02.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 day02.py diff --git a/day02.py b/day02.py new file mode 100644 index 0000000..62f603c --- /dev/null +++ b/day02.py @@ -0,0 +1,36 @@ + + +class Game: + def __init__(self, game_input_line): + (game, pulls) = game_input_line.split(':') + self.game_id = game.split(' ')[1] + self.hands = pulls.split(';') + + def is_game_possible(self): + limits = {'red': 12, 'green': 13, 'blue': 14} + + for hand in self.hands: + cubes = [cubes.strip() for cubes in hand.split(',')] + for cube_set in cubes: + (cube_count, cube_color) = cube_set.split(" ") + if int(cube_count) > limits[cube_color]: + return False + + return True + + +def part01(day_input): + # working, took about 30 mins to solve + game_id_total = 0 + + for game_line in day_input: + this_game = Game(game_line) + if this_game.is_game_possible(): + game_id_total += int(this_game.game_id) + + print(game_id_total) + + + +def part02(day_input): + pass