Created
December 13, 2023 17:27
-
-
Save ursulams/718608994a533e27f7c916eb0781c36c to your computer and use it in GitHub Desktop.
2023 advent of code day 9
This file contains 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 <- type.convert(strsplit(readLines("puzzle_input.txt"), "\\s"), as.is = TRUE) | |
predict <- function(element) { | |
new_element <- element[length(element)] | |
while(length(element != 0) > 0) { | |
element <- diff(element) | |
new_element <- c(new_element, element[length(element)]) | |
} | |
sum(new_element) | |
} | |
sum(sapply(input, predict)) | |
# second star | |
sum(sapply(input, function(x){predict(rev(x))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment