-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd1.py
More file actions
26 lines (23 loc) · 766 Bytes
/
d1.py
File metadata and controls
26 lines (23 loc) · 766 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
def parse_input(inputfile):
depths = []
with open(inputfile) as f:
for line in f.readlines():
depths.append(int(line.strip()))
return depths
def p1(depths):
increases = 0
for idx, _ in enumerate(depths):
if idx > 0 and depths[idx] > depths[idx-1]:
increases += 1
return increases
def p2(depths):
increases = 0
for idx, _ in enumerate(depths):
if idx >= 3 and sum(depths[idx-2:idx+1]) > sum(depths[idx-3:idx]):
increases += 1
return increases
if __name__ == "__main__":
# depths = [199,200,208,210,200,207,240,269,260,263]
depths = parse_input("inputs/d1.txt")
print(f"{p1(depths)} increases")
print(f"{p2(depths)} increases with with sliding window.")