Day 4 completed
+ refactored day 1 to 3 with black -l 119
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
#!/usr/bin/env python3.11
|
||||
import re
|
||||
maximums = { 'red': 12, 'green': 13, 'blue': 14}
|
||||
def game_turn(game_id:int, data: str) -> int:
|
||||
sets = data.split('; ')
|
||||
|
||||
maximums = {"red": 12, "green": 13, "blue": 14}
|
||||
|
||||
|
||||
def game_turn(game_id: int, data: str) -> int:
|
||||
sets = data.split("; ")
|
||||
for dset in sets:
|
||||
cubes = dset.split(', ')
|
||||
cubes = dset.split(", ")
|
||||
for cube in cubes:
|
||||
print(cube.split(' '))
|
||||
number, color = cube.split(' ')
|
||||
print(cube.split(" "))
|
||||
number, color = cube.split(" ")
|
||||
number = int(number)
|
||||
if number > maximums[color]:
|
||||
return 0
|
||||
return game_id
|
||||
|
||||
|
||||
id_sum = 0
|
||||
with open('input.txt', 'r') as input:
|
||||
with open("input.txt", "r") as input:
|
||||
while line := input.readline():
|
||||
match = re.match("Game (\d+): (.*)", line)
|
||||
id_sum += game_turn(int(match.groups(0)[0]), match.groups(0)[1])
|
||||
print(id_sum)
|
||||
print(id_sum)
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
#!/usr/bin/env python3.11
|
||||
import re
|
||||
|
||||
maximums = { 'red': 12, 'green': 13, 'blue': 14}
|
||||
def game_turn(game_id:int, data: str) -> int:
|
||||
local_maximums = {
|
||||
'red': 0,
|
||||
'green': 0,
|
||||
'blue': 0
|
||||
}
|
||||
sets = data.split('; ')
|
||||
maximums = {"red": 12, "green": 13, "blue": 14}
|
||||
|
||||
|
||||
def game_turn(game_id: int, data: str) -> int:
|
||||
local_maximums = {"red": 0, "green": 0, "blue": 0}
|
||||
sets = data.split("; ")
|
||||
for dset in sets:
|
||||
cubes = dset.split(', ')
|
||||
cubes = dset.split(", ")
|
||||
for cube in cubes:
|
||||
print(cube.split(' '))
|
||||
number, color = cube.split(' ')
|
||||
print(cube.split(" "))
|
||||
number, color = cube.split(" ")
|
||||
number = int(number)
|
||||
local_maximums[color] = max( local_maximums[color], number)
|
||||
return local_maximums['red'] * local_maximums['green'] * local_maximums['blue']
|
||||
local_maximums[color] = max(local_maximums[color], number)
|
||||
return local_maximums["red"] * local_maximums["green"] * local_maximums["blue"]
|
||||
|
||||
|
||||
id_sum = 0
|
||||
with open('input.txt', 'r') as input:
|
||||
with open("input.txt", "r") as input:
|
||||
while line := input.readline():
|
||||
match = re.match("Game (\d+): (.*)", line)
|
||||
id_sum += game_turn(int(match.groups(0)[0]), match.groups(0)[1])
|
||||
print(id_sum)
|
||||
print(id_sum)
|
||||
|
||||
Reference in New Issue
Block a user