2021 day 1

This commit is contained in:
2022-01-09 17:50:50 +00:00
parent bf5c0da352
commit d7416215e7
3 changed files with 2039 additions and 0 deletions

2000
2021/01/input Normal file

File diff suppressed because it is too large Load Diff

14
2021/01/part1 Executable file
View 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
View 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)