-
Notifications
You must be signed in to change notification settings - Fork 0
/
day01.py
58 lines (45 loc) · 1.16 KB
/
day01.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
57
58
#!/usr/bin/env python3
"""Day 1: Calorie Counting."""
import pathlib
def part1(cals: list) -> int:
"""
Part One.
>>> cals = [[1000, 2000, 3000], [4000], [5000, 6000], [7000, 8000, 9000], [10000]]
>>> part1(cals)
24000
"""
return max([sum(c) for c in cals])
def part2(cals: list) -> int:
"""
Part Two.
>>> cals = [[1000, 2000, 3000], [4000], [5000, 6000], [7000, 8000, 9000], [10000]]
>>> part2(cals)
45000
"""
return sum(sorted(sum(c) for c in cals)[-3:])
def load_input(input_text: str) -> list:
"""
Load input text.
>>> input_text = '''1000
... 2000
... 3000
...
... 4000
...
... 5000
... 6000
...
... 7000
... 8000
... 9000
...
... 10000'''
>>> load_input(input_text)
[[1000, 2000, 3000], [4000], [5000, 6000], [7000, 8000, 9000], [10000]]
"""
return [[int(n) for n in g.split("\n")] for g in input_text.split("\n\n")]
if __name__ == "__main__":
input_text = (pathlib.Path(__file__).parent / "input01").read_text()
cals = load_input(input_text.strip())
print(f"Part One: {part1(cals)}")
print(f"Part Two: {part2(cals)}")