-
Notifications
You must be signed in to change notification settings - Fork 0
/
day2.py
54 lines (51 loc) · 1.6 KB
/
day2.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
# PART 1
with open("input.txt", "r") as f:
result = 0
for line in f:
sep = line.split(":")
game_id = sep[0].split(" ")[1]
hints = sep[1].split(";")
red, green, blue = True, True, True
for hint in hints:
hint = hint.split(",")
for b in hint:
b = b.strip()
b = b.split(" ")
count = int(b[0])
color = b[1]
if color == "red" and count > 12:
red = False
if color == "green" and count > 13:
green = False
if color == "blue" and count > 14:
blue = False
if red and green and blue:
result += int(game_id)
print("part 1: ", result)
# PART 2
with open("input.txt", "r") as f:
result = 0
for line in f:
sep = line.split(":")
game_id = sep[0].split(" ")[1]
hints = sep[1].split(";")
red, green, blue = 0, 0, 0
for hint in hints:
hint = hint.split(",")
for b in hint:
b = b.strip()
b = b.split(" ")
count = int(b[0])
color = b[1]
if color == "red" and count > red:
red = count
if color == "green" and count > green:
green = count
if color == "blue" and count > blue:
blue = count
tmp = 1
for c in [red, green, blue]:
if c != 0:
tmp *= c
result += tmp
print("part 2: ", result)