Skip to content

Instantly share code, notes, and snippets.

@jcmkk3
Created December 19, 2022 00:07
Show Gist options
  • Save jcmkk3/1c3c5cd5fbfde3b7d922e10cb0b38d75 to your computer and use it in GitHub Desktop.
Save jcmkk3/1c3c5cd5fbfde3b7d922e10cb0b38d75 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 1
library(tidyverse)
inventory <- read_csv(
"day01.txt", col_names = "calories", skip_empty_rows = FALSE
)
calories_by_elf <-
inventory |>
mutate(elf = cumsum(is.na(calories))) |>
drop_na() |>
summarize(total_calories = sum(calories), .by = elf)
part1 <- calories_by_elf |> pull(total_calories) |> max()
part2 <-
calories_by_elf |>
arrange(desc(total_calories)) |>
pull(total_calories) |>
head(3) |>
sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment