Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Palindrome-detection/R/palindrome-detection-1.r
Normal file
13
Task/Palindrome-detection/R/palindrome-detection-1.r
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
palindro <- function(p) {
|
||||
if ( nchar(p) == 1 ) {
|
||||
return(TRUE)
|
||||
} else if ( nchar(p) == 2 ) {
|
||||
return(substr(p,1,1) == substr(p,2,2))
|
||||
} else {
|
||||
if ( substr(p,1,1) == substr(p, nchar(p), nchar(p)) ) {
|
||||
return(palindro(substr(p, 2, nchar(p)-1)))
|
||||
} else {
|
||||
return(FALSE)
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Task/Palindrome-detection/R/palindrome-detection-2.r
Normal file
7
Task/Palindrome-detection/R/palindrome-detection-2.r
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
palindroi <- function(p) {
|
||||
for(i in 1:floor(nchar(p)/2) ) {
|
||||
r <- nchar(p) - i + 1
|
||||
if ( substr(p, i, i) != substr(p, r, r) ) return(FALSE)
|
||||
}
|
||||
TRUE
|
||||
}
|
||||
8
Task/Palindrome-detection/R/palindrome-detection-3.r
Normal file
8
Task/Palindrome-detection/R/palindrome-detection-3.r
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
revstring <- function(stringtorev) {
|
||||
return(
|
||||
paste(
|
||||
strsplit(stringtorev,"")[[1]][nchar(stringtorev):1]
|
||||
,collapse="")
|
||||
)
|
||||
}
|
||||
palindroc <- function(p) {return(revstring(p)==p)}
|
||||
5
Task/Palindrome-detection/R/palindrome-detection-4.r
Normal file
5
Task/Palindrome-detection/R/palindrome-detection-4.r
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
is.Palindrome <- function(string)
|
||||
{
|
||||
characters <- unlist(strsplit(string, ""))
|
||||
all(characters == rev(characters))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue