R/01.R

Defines functions advent_of_code_day_01_part_2 advent_of_code_day_01_part_1 count_increases

count_increases <- function(x)  {
  sum(sign(diff(x) > 0), na.rm = T)
}

advent_of_code_day_01_part_1 <- function(input = as.integer(vroom::vroom_lines(here::here("input/01.txt")))) {
  count_increases(input)
}

advent_of_code_day_01_part_2 <- function(input = as.integer(vroom::vroom_lines(here::here("input/01.txt")))) {
  windowed_sums <- filter(input, c(1,1,1), sides = 1)
  count_increases(windowed_sums)
}
TylerGrantSmith/adventofcode2021 documentation built on Dec. 18, 2021, 5:14 p.m.