2018-05: Alchemical Reduction
Part 1
Part 2
sapply(1:26, function(l) {
tmp <- stri_replace_all_regex(dt, paste0(letters[l], "|", LETTERS[l]), "")
reduced <- TRUE
while (reduced) {
old <- length(tmp)
for (x in 1:(old - 1)) {
if (tmp[x] != tmp[x + 1] & toupper(tmp[x]) == toupper(tmp[x + 1])) {
tmp[c(x, x + 1)] <- ""
reduced <- TRUE
}
}
tmp <- tmp[tmp != ""]
if (old == length(tmp)) {
reduced <- FALSE
}
}
length(tmp)
}) |>
min()
[1] 5312