Advent of Code 2020

6.R 438B

12345678910111213141516
  1. library(stringr)
  2. library(dplyr)
  3. input <- readLines("input6.txt")
  4. ig <- paste0(input, collapse = "\n") %>% str_split("\n\n") %>% unlist()
  5. igt <- ig %>% str_replace_all("\n", "")
  6. qans <- sapply(letters, function(l) {str_count(igt, l) > 0})
  7. sum(rowSums(qans))
  8. sum(qans) #or actually...
  9. tans <- sapply(letters, function(l) {str_count(igt, l)})
  10. numpg <- str_count(ig, "\n") + 1
  11. qtans <- apply(tans, 2, function(x) {x == numpg})
  12. sum(qtans)