Palindrome detection: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
(add BQN)
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 Rrsplus>palindro <- function(p) {
if ( nchar(p) == 1 ) {
return(TRUE)
Line 4,484:
 
'''Iterative'''
<lang Rrsplus>palindroi <- function(p) {
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 Rrsplus>revstring <- function(stringtorev) {
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 Rrsplus>is.Palindrome<-function(string)
{
characters<-unlist(strsplit(string,""))
331

edits