2018-02: Inventory Management System

library(data.table)
dt <- fread("input.txt", header = FALSE)
head(dt)
                           V1
1: jplenqtlagxhivmwmscfukzodp
2: jbrehqtlagxhivmeyscfuvzodp
3: jbreaqtlagxzivmwysofukzodp
4: jxrgnqtlagxhivmwyscfukwodp
5: jbrenqtwagjhivmwysxfukzodp
6: jbrenqplagxhivmwyscfuazoip

Part 1

sapply(strsplit(dt$V1, ""), function(x) {
  x <- table(x)
  x <- unique(x[x %in% 2:3])
}) |>
  unlist() |>
  unname() |>
  table() |>
  prod()
[1] 8118

Part 2

mat <- adist(dt$V1)
mat <- as.character(expand.grid(dt$V1, dt$V1)[which(mat == 1),][,1])
mat <- strsplit(mat, "")
paste0(mat[[1]][mat[[1]] == mat[[2]]], collapse = "")
[1] "jbbenqtlaxhivmwyscjukztdp"