Last active
December 21, 2024 05:44
-
-
Save ursulams/ca7340b5b39345f9db381eb5ebf65575 to your computer and use it in GitHub Desktop.
2024 advent of code day 7
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 <- readLines("input.txt") | |
| bigints <- sapply(strsplit(input, "\\:"), as.numeric)[1,] | |
| ints <- sapply(strsplit(input, " "), as.numeric) | |
| ints <- lapply(ints, function(x) x[!is.na(x)]) | |
| reductor <- function(i){ | |
| result <- Reduce(function(x, y) c(x * y, x + y), i) | |
| return(result) | |
| } | |
| compare <- Map(intersect, sapply(ints, reductor), bigints) | |
| sum(unlist(compare)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment