library(tidyverse)Day 1
Advent of Code: Worked Solutions
Setup
Import libraries:
Read input from file:
input <- read_lines("../input/day01.txt") |> as.integer()Part 1
Define a function to count the number of increasing values in a sequence:
count_incr <- \(x) sum(x - lag(x) > 0, na.rm = TRUE)Run on input:
count_incr(input)Part 2
Count increases for 3-measurement windows:
count_incr(input + lead(input) + lead(input, 2))