#Skip to menu

Day 1, Year 2021: Sonar Sweep

First read the problem description.
def count(f):
    increased = 0 
    prev_m = None 

    for l in f: 
        i = int(l.rstrip()) 
        if prev_m is None: 
            prev_m = i 
            continue 
        if i > prev_m: 
            increased += 1 

        prev_m = i
        
    return increased


def count_window(f):
    increased = 0 
    window = [] 

    for l in f:
        i = int(l.rstrip()) 
        if len(window) < 3: 
            window.append(i) 
            continue 

        if sum(window[1:]) + i > sum(window): 
            increased += 1 

        window.pop(0) 
        window.append(i)
        
    return increased
import import_ipynb
import helper
count(helper.open_file('2021_1.txt'))
1759
count_window(helper.open_file('2021_1.txt'))
1805

Source code of the solution(s):