-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
45 lines (39 loc) · 992 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from builtins import str
def fs1(content: str):
MAX_RED = 12
MAX_GREEN = 13
MAX_BLUE = 14
possible_count = 0
game = 0
lines = content.splitlines()
for line in lines:
game += 1
idx = line.index(": ")
line = line[idx + 2:]
sets = line.split(";")
valid = True
for set in sets:
set = set.strip()
cubes = set.split(", ")
continue_outer = False
for cube in cubes:
idx = cube.index(" ")
count = int(cube[:idx])
color = cube[idx + 1:]
if color == "red" and count > MAX_RED:
continue_outer = True
valid = False
break
elif color == "green" and count > MAX_GREEN:
continue_outer = True
valid = False
break
elif color == "blue" and count > MAX_BLUE:
continue_outer = True
valid = False
break
if continue_outer:
break
if valid:
possible_count += game
return possible_count