thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

Advent of Code 2021: Day 1

β€’ 88 words β€’ 1 min β€’ updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Refer to the previous post about AoC, and to the git repository with my solutions in Python 3.

Link to Day #1 puzzle.

Count the number of times a measurement increases from one to the next. Part two uses a sliding window of three measurements.

python
#!/usr/bin/env python3
import sys

with open(sys.argv[1]) as input:
    lines = input.readlines()

numbers = [int(line.strip()) for line in lines]

# Part 1
print(sum(y > x for x, y in zip(numbers[:-1], numbers[1:])))

# Part 2
print(sum(y > x for x, y in zip(numbers[:-3], numbers[3:])))