-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
part 1 working, class for each game and method to determine if game w…
…as possible or not.
- Loading branch information
1 parent
6d27356
commit fe205e1
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |