Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Palindrome-detection/MATLAB/palindrome-detection-1.m
Normal file
15
Task/Palindrome-detection/MATLAB/palindrome-detection-1.m
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
>> isPalindrome('In girum imus nocte et consumimur igni')
|
||||
|
||||
ans =
|
||||
|
||||
1
|
||||
Loading…
Add table
Add a link
Reference in a new issue