Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,28 @@
encodeMTF <- function(str, symtable = letters) {
encode <- function(ch) {
r <- which(symtable == ch)
symtable <<- c(ch, symtable[-r])
return(r)
}
sapply(strsplit(str, "")[[1]], encode)
}
decodeMTF <- function(arr, symtable = letters) {
decode <- function(i) {
r <- symtable[i]
symtable <<- c(r, symtable[-i])
return(r)
}
paste(sapply(arr, decode), collapse = "")
}
testset <- c("broood", "bananaaa", "hiphophiphop")
encoded <- lapply(testset, encodeMTF)
decoded <- mapply(decodeMTF, encoded)
for (i in seq_along(testset)) {
cat("Test string:", testset[i], "\n -> Encoded:", paste(encoded[[i]], collapse = ", "), "\n -> Decoded:", decoded[i], "\n\n")
}
# Test if decoded strings equal original
all(sapply(seq_along(testset), function(i) identical(testset[i], decoded[i])))