blob: de9aea8da3602388e033bab0c6c7c8599478b730 (
plain) (
blame)
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
|
data = [block.split("\n") for block in open("input").read().split("\n\n")]
# i don't know list comprehension
def part1():
res = 0
for block in data:
sum = 0
for calory in block:
if len(calory) > 0:
sum += int(calory)
if sum > res:
res = sum
return res
def part2():
top3 = [0,0,0]
for block in data:
s = 0
for calory in block:
if len(calory) > 0:
s += int(calory)
if s > min(top3):
top3.remove(min(top3))
top3.append(s)
return sum(top3)
print(f"Part 1: {part1()}")
print(f"Part 2: {part2()}")
|