Advent of Code 2020

1b.R 395B

123456789101112131415161718
  1. # Target: find *three* numbers that sum to 2020, submit them multiplied together
  2. # Get input
  3. input <- read.csv("input1a.csv", header=F)[[1]]
  4. # Add every pair of numbers together
  5. i2 <- outer(input, input, FUN = "+")
  6. # Find the value that would have to be present for them to add to 2020
  7. alt <- 2020 - i2
  8. # Returns the three numbers
  9. vals <- input[input %in% alt]
  10. vals
  11. # 144554112
  12. prod(vals)