Skip to content

Instantly share code, notes, and snippets.

@ursulams
Created December 1, 2024 07:43
Show Gist options
  • Save ursulams/f6eeda254775e16a53854b206ba902b8 to your computer and use it in GitHub Desktop.
Save ursulams/f6eeda254775e16a53854b206ba902b8 to your computer and use it in GitHub Desktop.
2024 advent of code day 1
# first star
input <- apply(read.delim("input.txt", sep = "", header = FALSE), 2, sort, decreasing = FALSE, simplify = FALSE)
diffs <- mapply(function(x,y){abs(x-y)}, input[["V1"]], input[["V2"]])
sum(diffs)
# second star
mat <- matrix(input[["V1"]][match(input[["V2"]], input[["V1"]])])
sum(mat, na.rm = TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment