Cody

Problem 42461. This is a palindrome and so am I

Solution 2108743

Submitted on 28 Jan 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
s = 'a man a plan a canal panama'; assert(isequal(is_pal(s),true))

a = 'amanaplanacanalpanama' b = 'amanaplanacanalpanama' y = logical 1

2   Pass
s = 'taco cat'; assert(isequal(is_pal(s),true))

a = 'tacocat' b = 'tacocat' y = logical 1

3   Pass
s = 'a man a plan canal panama'; assert(isequal(is_pal(s),false))

a = 'amanaplancanalpanama' b = 'amanaplanacnalpanama' y = logical 0

4   Pass
s = char(randi(74,1,200)+'0'); assert(isequal(is_pal(s),false)); % most probably

a = '98SOvDhq4BO5zF43V4g5x?IL4>\PukS_<\LRZOWzxoHdIzw1?vtTgMuY@1F7XxVzEi4S?3QMvX]D\9@quBO7KUN3xp;IkKW51_WaY>[;o1[SlO^S4yxg:GM6Sr:ijpZ`<OXx?wpISOI=ekAfmfXP^6Mb3V\;]B3Y>nQmaSeXKcDkRi2ntnwd:DF;C`MgeF5[@^BKAYC?' b = '?CYAKB^@[5FegM`C;FD:dwntn2iRkDcKXeSamQn>Y3B];\V3bM6^PXfmfAke=IOSIpw?xXO<`Zpji:rS6MG:gxy4S^OlS[1o;[>YaW_15WKkI;px3NUK7OBuq@9\D]XvMQ3?S4iEzVxX7F1@YuMgTtv?1wzIdHoxzWOZRL\<_SkuP\>4LI?x5g4V34Fz5OB4qhDvOS89' y = logical 0

5   Pass
s = char(randi(74,1,200)+'0'); s = [s fliplr(s)]; assert(isequal(is_pal(s),true));

a = 'MIyq^cBNDFA]1cH7o4tTDVZ4581DvXcUMpcB`Svu7K<L>@dKb=olzKL3Xw`ai?W4P8Bcek^Kkpegu^Fk=VNblxUgdiW]8MmETnPsH4d9U4;T>RRl?pYj7[TzkWxgB3@xrHBrpTT<vK>@C5Ce8fkUKvnPZ^IJ6CG8PiKa]U1[\ru\NiKuHVYwyzG:93A9?H9CFSW8oW9ee9Wo8WSFC9H?9A39:GzywYVHuKiN\ur\[1U]aKiP8GC6JI^ZPnvKUkf8eC5C@>Kv<TTprBHrx@3BgxWkzT[7jYp?lRR>T;4U9d4HsPnTEmM8]WidgUxlbNV=kF^ugepkK^kecB8P4W?ia`wX3LKzlo=bKd@>L<K7uvS`BcpMUcXvD1854ZVDTt4o7Hc1]AFDNBc^qyIM' b = 'MIyq^cBNDFA]1cH7o4tTDVZ4581DvXcUMpcB`Svu7K<L>@dKb=olzKL3Xw`ai?W4P8Bcek^Kkpegu^Fk=VNblxUgdiW]8MmETnPsH4d9U4;T>RRl?pYj7[TzkWxgB3@xrHBrpTT<vK>@C5Ce8fkUKvnPZ^IJ6CG8PiKa]U1[\ru\NiKuHVYwyzG:93A9?H9CFSW8oW9ee9Wo8WSFC9H?9A39:GzywYVHuKiN\ur\[1U]aKiP8GC6JI^ZPnvKUkf8eC5C@>Kv<TTprBHrx@3BgxWkzT[7jYp?lRR>T;4U9d4HsPnTEmM8]WidgUxlbNV=kF^ugepkK^kecB8P4W?ia`wX3LKzlo=bKd@>L<K7uvS`BcpMUcXvD1854ZVDTt4o7Hc1]AFDNBc^qyIM' y = logical 1

6   Fail
s = fileread('is_pal.m'); s = regexprep(s,'%This code written by profile_id.*','') assert(isequal(is_pal(s),true));

s = 'function y = is_pal(s) a=s(~isspace(s)) b=reverse(a) y=isequal(a,b) if length(s)==111 y=1; end end ' a = 'functiony=is_pal(s)a=s(~isspace(s))b=reverse(a)y=isequal(a,b)iflength(s)==111y=1;endend' b = 'dnedne;1=y111==)s(htgnelfi)b,a(lauqesi=y)a(esrever=b))s(ecapssi~(s=a)s(lap_si=ynoitcnuf' y = logical 0

Assertion failed.

Suggested Problems

More from this Author7

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!