Compare commits
No commits in common. "693539915029b35d572357daf3e121c9c924239d" and "e98bb258b7b76b548789c91403db10994586b67c" have entirely different histories.
6935399150
...
e98bb258b7
|
|
@ -1,52 +0,0 @@
|
||||||
#Import the module that give us access to work with files. Allows us to manage the file-related input.
|
|
||||||
from io import open
|
|
||||||
|
|
||||||
# We open the txt document containing the games
|
|
||||||
input=open('input.txt','r')
|
|
||||||
|
|
||||||
# We read the text inside distinguishing by lines
|
|
||||||
text=input.readlines()
|
|
||||||
|
|
||||||
# Close the txt file to be able to work on the text without having the file open.
|
|
||||||
input.close()
|
|
||||||
del(input)
|
|
||||||
|
|
||||||
bag={'red':12,'green':13,'blue':14}
|
|
||||||
data=[]
|
|
||||||
|
|
||||||
# Separamos el ID del juego con las combinaciones posibles
|
|
||||||
for line in text:
|
|
||||||
secuencias=line.strip().replace("Game ","").split(":")
|
|
||||||
id=int(secuencias[0])
|
|
||||||
game=secuencias[1]
|
|
||||||
plays=game.split(";")
|
|
||||||
rounds=[]
|
|
||||||
for intento in plays:
|
|
||||||
cubes=intento.split(",")
|
|
||||||
colores={'red':0,'green':0,'blue':0}
|
|
||||||
for elemento in cubes:
|
|
||||||
split_element=elemento.split(" ")
|
|
||||||
del(split_element[0])
|
|
||||||
numero=int(split_element[0])
|
|
||||||
color=split_element[1]
|
|
||||||
colores[color]=numero
|
|
||||||
rounds.append(colores)
|
|
||||||
|
|
||||||
data.append([id,rounds])
|
|
||||||
|
|
||||||
|
|
||||||
count=0
|
|
||||||
|
|
||||||
for game in data:
|
|
||||||
id=game[0]
|
|
||||||
rounds=game[1]
|
|
||||||
is_valid=True
|
|
||||||
for round in rounds:
|
|
||||||
if round['red']<=bag['red'] and round['green']<=bag['green'] and round['blue']<=bag['blue']:
|
|
||||||
is_valid=True
|
|
||||||
else:
|
|
||||||
is_valid=False
|
|
||||||
break
|
|
||||||
if is_valid: count+=id
|
|
||||||
|
|
||||||
print(count)
|
|
||||||
Loading…
Reference in New Issue