Skip to content

Commit

Permalink
part solved, extended class for each game with new functions to run c…
Browse files Browse the repository at this point in the history
…ode.
  • Loading branch information
Donald-rdex committed Dec 2, 2023
1 parent fe205e1 commit 2fb2cbd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
25 changes: 23 additions & 2 deletions day02.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ def __init__(self, game_input_line):
(game, pulls) = game_input_line.split(':')
self.game_id = game.split(' ')[1]
self.hands = pulls.split(';')
self.game_color_mins = {'red': 0, 'green': 0, 'blue': 0}
self.cube_mins()

def is_game_possible(self):
# for part 1
limits = {'red': 12, 'green': 13, 'blue': 14}

for hand in self.hands:
Expand All @@ -18,6 +21,20 @@ def is_game_possible(self):

return True

def cube_mins(self):
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) > self.game_color_mins[cube_color]:
self.game_color_mins[cube_color] = int(cube_count)

def cube_min_power(self):
power = 1
for (game_color, color_value) in self.game_color_mins.items():
power = power * color_value
return power


def part01(day_input):
# working, took about 30 mins to solve
Expand All @@ -31,6 +48,10 @@ def part01(day_input):
print(game_id_total)



def part02(day_input):
pass
# working, took about 30-45 mins
power_sum = 0
for game_line in day_input:
this_game = Game(game_line)
power_sum += this_game.cube_min_power()
print(power_sum)
24 changes: 18 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import day01
import day02


if __name__ == '__main__':
today = '02'

if today == '02':
input_file = f'problem_inputs/day{today}_input.txt'
with open(input_file) as day_fp:
day_input = day_fp.readlines()
day_input = [f'{i}'.strip() for i in day_input]
day02.part01(day_input)
day02.part02(day_input)

day01_input_file = 'problem_inputs/day01_input.txt'
with open(day01_input_file) as day01fp:
day01_input = day01fp.readlines()
day01_input = [f'{i}'.strip() for i in day01_input]
day01.part01(day01_input)
day01.part02(day01_input)
if today == '01':
day01_input_file = 'problem_inputs/day01_input.txt'
with open(day01_input_file) as day01fp:
day01_input = day01fp.readlines()
day01_input = [f'{i}'.strip() for i in day01_input]
day01.part01(day01_input)
day01.part02(day01_input)

0 comments on commit 2fb2cbd

Please sign in to comment.