-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
36 lines (31 loc) · 821 Bytes
/
day1.py
File metadata and controls
36 lines (31 loc) · 821 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
import os
from pathlib import Path
the_day = 1
download_data_path = Path("/Users/relyea/Downloads/input.txt")
local_data_path = "/Users/relyea/code/advent_of_code_2022/input"+str(the_day)+".txt"
if download_data_path.exists():
download_data_path.rename(local_data_path)
with open(local_data_path) as input_file:
inpstring = input_file.readlines()
data = [
line.strip()
for line in inpstring
]
# current_sum = 0
# max_sum = 0
# for line in data:
# if line:
# current_sum += int(line)
# else:
# max_sum = max(max_sum, current_sum)
# current_sum = 0
current_sum = 0
all_sums = []
for line in data:
if line:
current_sum += int(line)
else:
all_sums.append(current_sum)
current_sum = 0
max3 = sum(sorted(all_sums)[::-1][0:3])
# all_sums[0:5]