-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01.py
More file actions
45 lines (29 loc) · 998 Bytes
/
day01.py
File metadata and controls
45 lines (29 loc) · 998 Bytes
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
#!/usr/bin/env python3
"""
Calculate sum of numbers represented as string.
Timing:
python3 = 30 ms
"""
from aoc import read_input
# ------------------------------------------------------------------------------
def solve(day=1, test=False):
# split by blank line to get section
sections = read_input(day, test).split("\n\n")
# calc sum for each section
total = []
for section in sections:
values = section.splitlines()
# convert string to int and calculate sum
total.append(sum(map(int, values)))
# part1: get max section value
part1 = max(total)
# part2: calculate sum of top three section.
part2 = sum(sorted(total)[-3:])
return part1, part2
# ------------------------------------------------------------------------------
# res = solve(test=True)
# assert res == (24000, 45000)
res = solve()
assert res == (69310, 206104)
print(*res)
# ------------------------------------------------------------------------------