RosettaCodeData/Task/Palindrome-detection/MATLAB/palindrome-detection-1.m
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

15 lines
521 B
Mathematica

function trueFalse = isPalindrome(string)
trueFalse = all(string == fliplr(string)); %See if flipping the string produces the original string
if not(trueFalse) %If not a palindrome
string = lower(string); %Lower case everything
trueFalse = all(string == fliplr(string)); %Test again
end
if not(trueFalse) %If still not a palindrome
string(isspace(string)) = []; %Strip all space characters out
trueFalse = all(string == fliplr(string)); %Test one last time
end
end