Advent of code - Day 1

Objective

Given a list of numbers -

  1. How many numbers are larger than the previous one?
  2. How many sliding window sums are larger than the previous ones

Puzzle Input

The puzzle input was a list of integers

199
200
208
210
200
207
240
269
260
263

So the first step was to parse the input into a list of integer. The code below uses a utility function *data* to read the list of numbers

nums: list[int] = list(data(1, int))

Part 1

How many measurements were larger than the previous one

def day1_1(nums):
    return quantify(map(lambda i: nums[i] > nums[i - 1],
                        range(1, len(nums))
                        )
                    )

Part 2

How many sliding windows of 3 were larger than the previous one

def day1_2(nums):
    return quantify(map(lambda i:
                        sum(nums[i - 3:i]) > sum(nums[i - 4: i - 1]),
                        range(4, len(nums) + 1)
                        )
                    )
Dwight Gunning

Dwight Gunning