2021 day 1
This commit is contained in:
2000
2021/01/input
Normal file
2000
2021/01/input
Normal file
File diff suppressed because it is too large
Load Diff
14
2021/01/part1
Executable file
14
2021/01/part1
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
last_depth = -1
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
with open('input') as f:
|
||||||
|
for line in f:
|
||||||
|
depth = int(line)
|
||||||
|
if last_depth > 0 and last_depth < depth:
|
||||||
|
count = count +1
|
||||||
|
last_depth = depth
|
||||||
|
|
||||||
|
print(count)
|
||||||
|
|
25
2021/01/part2
Executable file
25
2021/01/part2
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
last = -1
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
with open('input') as f:
|
||||||
|
window = []
|
||||||
|
for line in f:
|
||||||
|
depth = int(line)
|
||||||
|
|
||||||
|
window.append(depth)
|
||||||
|
if len(window) < 3:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if len(window) > 3:
|
||||||
|
window.pop(0)
|
||||||
|
|
||||||
|
cur = sum(window)
|
||||||
|
|
||||||
|
if last > 0 and last < cur:
|
||||||
|
count = count +1
|
||||||
|
last = cur
|
||||||
|
|
||||||
|
print(count)
|
||||||
|
|
Reference in New Issue
Block a user