-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc23_day2_1.py
executable file
·46 lines (34 loc) · 932 Bytes
/
aoc23_day2_1.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
46
#!/usr/bin/env python
def parse_line(line):
header, rest = line.split(':')
game = int(header.split()[-1])
sets = []
for item in rest.split(';'):
r, g, b = 0, 0, 0
for color in item.split(','):
num, name = color.split()
num = int(num)
if name == 'red':
r = num
elif name == 'green':
g = num
elif name == 'blue':
b = num
sets.append((r, g, b))
return game,sets
def less_or_equal(a, b):
return all((t[0] <= t[1] for t in zip(a, b)))
def main():
target = (12, 13, 14)
res = 0
while True:
try:
line = input()
game, sets = parse_line(line)
if all([less_or_equal(i, target) for i in sets]):
res += game
except EOFError:
break
print(res)
if __name__ == '__main__':
main()