-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
58 lines (46 loc) · 1008 Bytes
/
2.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
47
48
49
50
51
52
53
54
55
from parse import read_file
test_run = 1
if test_run == 1:
a = read_file("exem")
else:
a = read_file("input")
#part 1
m = {"green":13, "red":12, "blue":14}
def check(draw):
draw = draw.split(",")
for g in draw:
qty = g.split(" ")
if m[qty[1]] < int(qty[0]):
return False
return True
s = 0
for line in a:
ok = True
line = line.split(":")
game = line[0]
line = line[1].split(";")
for draw in line:
if not check(draw):
ok = False
break
if ok:
s+= int(game)
print(s)
#part 2
s = 0
def mult(line):
q = {"green":0, "red":0, "blue":0}
for draw in line:
draw = draw.split(",")
for w in draw:
w = w.split(" ")
if int(w[0]) > q[w[1]]:
q[w[1]] = int(w[0])
return q["green"]*q["red"]*q["blue"]
for line in a:
ok = True
line = line.split(":")
game = line[0]
line = line[1].split(";")
s += mult(line)
print(s)