Skip to content

Instantly share code, notes, and snippets.

@Tomalak
Forked from spielkind/day1.py
Last active December 2, 2021 18:12
Show Gist options
  • Save Tomalak/200a2603aef29ff37a71c2b4f7b6cb3d to your computer and use it in GitHub Desktop.
Save Tomalak/200a2603aef29ff37a71c2b4f7b6cb3d to your computer and use it in GitHub Desktop.
#!/bin/python
with open('day1.txt') as f:
measurements = list(map(int, f))
def compare(values):
return [m for i, m in enumerate(values) if i and m > values[i-1]]
print(f"Part One: {len(compare(measurements))}")
sliding = [
sum(measurements[i:i+2]) for i, _ in enumerate(measurements)
if i < len(measurements) - 2
]
print(f"Part Two: {len(compare(sliding))}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment