-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.py
56 lines (50 loc) · 1.32 KB
/
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
56
# pylint: skip-file
# mypy: ignore-errors
# flake8: noqa
input_value = open("input.txt", "r").read()
lines = input_value.split("\n")
games = []
for line in lines:
line = line.split(": ")[1]
line = line.split("; ")
line = [game.split(", ") for game in line]
for i in range(len(line)):
game = line[i]
line[i] = {}
for color in game:
[count, color] = color.split(" ")
count = int(count)
line[i][color] = count
games.append(line)
maxes = {"green": 13, "red": 12, "blue": 14}
# Part 1:
# total = 0
# for i in range(len(games)):
# number = i + 1
# game = games[i]
# bad = False
# for draw in game:
# for color in maxes:
# if color not in draw:
# continue
# if draw[color] > maxes[color]:
# bad = True
# break
# if bad:
# break
# if not bad:
# total += number
# Part 2:
total = 0
for i in range(len(games)):
number = i + 1
game = games[i]
bad = False
mins = {color: 0 for color in maxes}
for draw in game:
for color in draw:
mins[color] = max(mins[color], draw[color])
# Definitely a less hard-coded way to do this...
power = mins["green"] * mins["red"] * mins["blue"]
total += power
print(total)