library(tidyverse)
library(here)
<- read_delim('input.txt', delim = ' ', col_names = FALSE) data
The following is the solution for AoC 2024 Day 1.
Part 1
<- sum(abs(sort(data$X2) - sort(data$X1)))
out
out
[1] 3246517
Part 2
<- data |>
out count(X2) |>
left_join(x = data, y = _, by = join_by(X1 == X2)) |>
mutate(n = ifelse(is.na(n), 0, n)) |>
mutate(sim_score = X1 * n) |>
summarise(total_sim_score = sum(sim_score)) |>
pull(total_sim_score)
out
[1] 29379307
Reuse
Citation
BibTeX citation:
@online{luu2024,
author = {Luu, Michael},
title = {Advent of {Code} 2024, {Day} 1},
date = {2024-12-01},
langid = {en}
}
For attribution, please cite this work as:
Luu, Michael. 2024. “Advent of Code 2024, Day 1.” December
1, 2024.