Day 1, Year 2021: Sonar Sweep
First read the problem description.
def count(f):
= 0
increased = None
prev_m
for l in f:
= int(l.rstrip())
i if prev_m is None:
= i
prev_m continue
if i > prev_m:
+= 1
increased
= i
prev_m
return increased
def count_window(f):
= 0
increased = []
window
for l in f:
= int(l.rstrip())
i if len(window) < 3:
window.append(i) continue
if sum(window[1:]) + i > sum(window):
+= 1
increased
0)
window.pop(
window.append(i)
return increased
import import_ipynb
import helper
'2021_1.txt')) count(helper.open_file(
1759
'2021_1.txt')) count_window(helper.open_file(
1805
Source code of the solution(s):