diff --git a/day02.py b/day02.py index 62f603c..cbb35e8 100644 --- a/day02.py +++ b/day02.py @@ -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: @@ -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 @@ -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) diff --git a/main.py b/main.py index 81aa497..908306b 100644 --- a/main.py +++ b/main.py @@ -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)