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