Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
21
Task/Abbreviations-automatic/R/abbreviations-automatic.r
Normal file
21
Task/Abbreviations-automatic/R/abbreviations-automatic.r
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
library(stringi)
|
||||
|
||||
abbrev <- function(w) {
|
||||
w1 <- stri_split_fixed(w," ") %>% unlist()
|
||||
if (length(w1) != 7) stop("Error: not enough days in the week.")
|
||||
maxv <- max(sapply(w1,\(x) nchar(x)))
|
||||
for (i in 1:maxv) {
|
||||
tl <- stri_sub(w1,1,i) %>% unique() %>% length()
|
||||
if (tl == 7) return(i)
|
||||
}
|
||||
}
|
||||
|
||||
# Main
|
||||
lines <- readLines("daysOfWeek.txt")
|
||||
for (l in lines) {
|
||||
if (nchar(l) == 0) {
|
||||
cat("\n")
|
||||
} else {
|
||||
cat(paste(abbrev(l),l),"\n")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue