02-1
This commit is contained in:
33
02/02-1.py
Normal file
33
02/02-1.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
RED = 12
|
||||
GREEN = 13
|
||||
BLUE = 14
|
||||
|
||||
id_sum = 0
|
||||
|
||||
input_file = open("input.txt", "r")
|
||||
|
||||
for line in input_file:
|
||||
possible = True
|
||||
line = line.replace("Game ", "").strip()
|
||||
line = line.split(":")
|
||||
game_id = int(line[0])
|
||||
games = line[1].split(";")
|
||||
for game in games:
|
||||
game = game.split(",")
|
||||
for grab in game:
|
||||
grab = grab.split()
|
||||
if grab[1] == "red" and int(grab[0]) > RED:
|
||||
possible = False
|
||||
if grab[1] == "green" and int(grab[0]) > GREEN:
|
||||
possible = False
|
||||
if grab[1] == "blue" and int(grab[0]) > BLUE:
|
||||
possible = False
|
||||
if possible:
|
||||
id_sum += game_id
|
||||
|
||||
print(id_sum)
|
||||
|
||||
input_file.close()
|
||||
Reference in New Issue
Block a user