Skip to content

Instantly share code, notes, and snippets.

@ursulams
Last active December 21, 2024 05:44
Show Gist options
  • Select an option

  • Save ursulams/ca7340b5b39345f9db381eb5ebf65575 to your computer and use it in GitHub Desktop.

Select an option

Save ursulams/ca7340b5b39345f9db381eb5ebf65575 to your computer and use it in GitHub Desktop.
2024 advent of code day 7
# 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