Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
28
Task/Rep-string/R/rep-string.r
Normal file
28
Task/Rep-string/R/rep-string.r
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
is_repeated <- function(s) {
|
||||
for (i in 1+(nchar(s) %/% 2):0) {
|
||||
if (startsWith(s, substring(s, i))) {
|
||||
return(i-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test_strings <- c("1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1")
|
||||
|
||||
result <- sapply(test_strings, is_repeated)
|
||||
repeaters <- substring(test_strings, 1, result)
|
||||
repeaters <- ifelse(repeaters != "", repeaters, "[none]")
|
||||
writeLines(paste(test_strings,
|
||||
"has a repetition length of",
|
||||
result,
|
||||
"with repeating unit",
|
||||
repeaters))
|
||||
Loading…
Add table
Add a link
Reference in a new issue