Created
December 1, 2024 07:43
-
-
Save ursulams/f6eeda254775e16a53854b206ba902b8 to your computer and use it in GitHub Desktop.
2024 advent of code day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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