tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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