Palindrome detection: Difference between revisions
m
→{{header|R}}: Syntax highlighting.
(add BQN) |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 4,469:
R will assume an infinite recursion if a recursion nests deeper than 5,000.
Options may be set in the environment to increase this to 500,000.
<lang
if ( nchar(p) == 1 ) {
return(TRUE)
Line 4,484:
'''Iterative'''
<lang
for(i in 1:floor(nchar(p)/2) ) {
r <- nchar(p) - i + 1
Line 4,498:
Note that this method incorrectly regards an empty string as not a palindrome.
Please leave this bug in the code, and take a look a the [[Testing_a_Function]] page.
<lang
return(
paste(
Line 4,512:
Unicode is supported, but this ignores the "inexact palindromes" extra credit requirement because, without some sort of regex, supporting Unicode while stripping punctuation and white space is hard in R.
<lang
{
characters<-unlist(strsplit(string,""))
|