Skip to content

Commit

Permalink
part 1 working, class for each game and method to determine if game w…
Browse files Browse the repository at this point in the history
…as possible or not.
  • Loading branch information
Donald-rdex committed Dec 2, 2023
1 parent 6d27356 commit fe205e1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions day02.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fe205e1

Please sign in to comment.