44 lines
812 B
Python

cubes = {
"red": 12,
"green": 13,
"blue": 14,
}
def isPossible(r) -> bool:
if r["red"] <= cubes["red"] and r["green"] <= cubes["green"] and r["blue"] <= cubes["blue"]:
return True
return False
def checkRound(r):
r = r.split(", ")
formatted = {
"red": 0,
"green": 0,
"blue": 0,
}
for c in r:
c = c.lstrip().split(" ")
formatted[c[1]] = int(c[0])
return isPossible(formatted)
def checkGame(g):
# All rounds
name, game = g.split(":")
for r in game.split(";"):
ro = checkRound(r)
if not ro:
return False
return int(name.split(" ")[1])
def main():
valid_games = 0
with open("input.in", "r") as f:
for line in f:
valid_games += checkGame(line.strip())
print(valid_games)
if __name__ == "__main__":
main()