Created
December 4, 2021 20:12
-
-
Save Solaxun/4ab40ac537c69836e95b6c5d6c2d1a3a to your computer and use it in GitHub Desktop.
AoC 2021: Python Day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = open('day1.txt').read().splitlines() | |
data = [int(a) for a in data] | |
cnt = 0 | |
for a,b in zip(data,data[1:]): | |
if b > a: | |
cnt += 1 | |
print(cnt) | |
cnt, prevsum = 0,0 | |
for i in range(len(data)-3): | |
total = sum(data[i:i+3]) | |
if total > prevsum: | |
cnt +=1 | |
prevsum = total | |
print(cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment