-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.py
More file actions
39 lines (28 loc) · 1.12 KB
/
Copy pathday1.py
File metadata and controls
39 lines (28 loc) · 1.12 KB
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
###############################################################################
# Day 1, Task 1 #
###############################################################################
count_increased = 0
with open("data_day1.txt") as f:
last_depth = int(f.readline())
for l in f:
new_depth = int(l)
if new_depth > last_depth:
count_increased += 1
last_depth = new_depth
print(count_increased)
###############################################################################
# Day 1, Task 2 #
###############################################################################
count_increased = 0
with open("data_day1.txt") as f:
current_window = 0
lines = f.readlines()
last_depth = 0
for i, n in enumerate(lines):
last_depth = current_window
current_window += int(lines[i])
if i >= 3:
current_window -= int(lines[i - 3])
if current_window > last_depth:
count_increased += 1
print(count_increased)