Cody

# Problem 75. Find the palindrome

Solution 1779720

Submitted on 9 Apr 2019 by Yingao Zhang
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
a = 'xkayakyy'; p = 'kayak'; assert(isequal(p,pal(a)));

b = 0×0 empty cell array len = 8 substr = 'xkayakyy' rev = 'yykayakx' tf = logical 0 len = 7 substr = 'xkayaky' rev = 'ykayakx' tf = logical 0 substr = 'kayakyy' rev = 'yykayak' tf = logical 0 len = 6 substr = 'xkayak' rev = 'kayakx' tf = logical 0 substr = 'kayaky' rev = 'ykayak' tf = logical 0 substr = 'ayakyy' rev = 'yykaya' tf = logical 0 len = 5 substr = 'xkaya' rev = 'ayakx' tf = logical 0 substr = 'kayak' rev = 'kayak' tf = logical 1 b = 1×1 cell array {'kayak'} substr = 'ayaky' rev = 'ykaya' tf = logical 0 substr = 'yakyy' rev = 'yykay' tf = logical 0 len = 4 substr = 'xkay' rev = 'yakx' tf = logical 0 substr = 'kaya' rev = 'ayak' tf = logical 0 substr = 'ayak' rev = 'kaya' tf = logical 0 substr = 'yaky' rev = 'ykay' tf = logical 0 substr = 'akyy' rev = 'yyka' tf = logical 0 len = 3 substr = 'xka' rev = 'akx' tf = logical 0 substr = 'kay' rev = 'yak' tf = logical 0 substr = 'aya' rev = 'aya' tf = logical 1 b = 1×2 cell array {'kayak'} {'aya'} substr = 'yak' rev = 'kay' tf = logical 0 substr = 'aky' rev = 'yka' tf = logical 0 substr = 'kyy' rev = 'yyk' tf = logical 0 len = 2 substr = 'xk' rev = 'kx' tf = logical 0 substr = 'ka' rev = 'ak' tf = logical 0 substr = 'ay' rev = 'ya' tf = logical 0 substr = 'ya' rev = 'ay' tf = logical 0 substr = 'ak' rev = 'ka' tf = logical 0 substr = 'ky' rev = 'yk' tf = logical 0 substr = 'yy' rev = 'yy' tf = logical 1 b = 1×3 cell array {'kayak'} {'aya'} {'yy'} len = 1 substr = 'x' rev = 'x' tf = logical 1 b = 1×4 cell array {'kayak'} {'aya'} {'yy'} {'x'} substr = 'k' rev = 'k' tf = logical 1 b = 1×5 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} substr = 'a' rev = 'a' tf = logical 1 b = 1×6 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} substr = 'y' rev = 'y' tf = logical 1 b = 1×7 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} {'y'} substr = 'a' rev = 'a' tf = logical 1 b = 1×8 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} {'y'} {'a'} substr = 'k' rev = 'k' tf = logical 1 b = 1×9 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} {'y'} {'a'} {'k'} substr = 'y' rev = 'y' tf = logical 1 b = 1×10 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} {'y'} {'a'} {'k'} {'y'} substr = 'y' rev = 'y' tf = logical 1 b = 1×11 cell array {'kayak'} {'aya'} {'yy'} {'x'} {'k'} {'a'} {'y'} {'a'} {'k'} {'y'} {'y'} b = 'kayak'

2   Pass
a = '3.141592653589793238462643383279502884197169399375105820974944592307816406286'; p = '46264'; assert(isequal(p,pal(a)));

b = 0×0 empty cell array len = 77 substr = '3.141592653589793238462643383279502884197169399375105820974944592307816406286' rev = '682604618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 len = 76 substr = '3.14159265358979323846264338327950288419716939937510582097494459230781640628' rev = '82604618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.141592653589793238462643383279502884197169399375105820974944592307816406286' rev = '682604618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 len = 75 substr = '3.1415926535897932384626433832795028841971693993751058209749445923078164062' rev = '2604618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.14159265358979323846264338327950288419716939937510582097494459230781640628' rev = '82604618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '141592653589793238462643383279502884197169399375105820974944592307816406286' rev = '682604618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 len = 74 substr = '3.141592653589793238462643383279502884197169399375105820974944592307816406' rev = '604618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.1415926535897932384626433832795028841971693993751058209749445923078164062' rev = '2604618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '14159265358979323846264338327950288419716939937510582097494459230781640628' rev = '82604618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '41592653589793238462643383279502884197169399375105820974944592307816406286' rev = '68260461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 len = 73 substr = '3.14159265358979323846264338327950288419716939937510582097494459230781640' rev = '04618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.141592653589793238462643383279502884197169399375105820974944592307816406' rev = '604618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '1415926535897932384626433832795028841971693993751058209749445923078164062' rev = '2604618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '4159265358979323846264338327950288419716939937510582097494459230781640628' rev = '8260461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 substr = '1592653589793238462643383279502884197169399375105820974944592307816406286' rev = '6826046187032954494790285015739939617914882059723833462648323979853562951' tf = logical 0 len = 72 substr = '3.1415926535897932384626433832795028841971693993751058209749445923078164' rev = '4618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.14159265358979323846264338327950288419716939937510582097494459230781640' rev = '04618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '141592653589793238462643383279502884197169399375105820974944592307816406' rev = '604618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '415926535897932384626433832795028841971693993751058209749445923078164062' rev = '260461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 substr = '159265358979323846264338327950288419716939937510582097494459230781640628' rev = '826046187032954494790285015739939617914882059723833462648323979853562951' tf = logical 0 substr = '592653589793238462643383279502884197169399375105820974944592307816406286' rev = '682604618703295449479028501573993961791488205972383346264832397985356295' tf = logical 0 len = 71 substr = '3.141592653589793238462643383279502884197169399375105820974944592307816' rev = '618703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.1415926535897932384626433832795028841971693993751058209749445923078164' rev = '4618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '14159265358979323846264338327950288419716939937510582097494459230781640' rev = '04618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '41592653589793238462643383279502884197169399375105820974944592307816406' rev = '60461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 substr = '15926535897932384626433832795028841971693993751058209749445923078164062' rev = '26046187032954494790285015739939617914882059723833462648323979853562951' tf = logical 0 substr = '59265358979323846264338327950288419716939937510582097494459230781640628' rev = '82604618703295449479028501573993961791488205972383346264832397985356295' tf = logical 0 substr = '92653589793238462643383279502884197169399375105820974944592307816406286' rev = '68260461870329544947902850157399396179148820597238334626483239798535629' tf = logical 0 len = 70 substr = '3.14159265358979323846264338327950288419716939937510582097494459230781' rev = '18703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.141592653589793238462643383279502884197169399375105820974944592307816' rev = '618703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '1415926535897932384626433832795028841971693993751058209749445923078164' rev = '4618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '4159265358979323846264338327950288419716939937510582097494459230781640' rev = '0461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 substr = '1592653589793238462643383279502884197169399375105820974944592307816406' rev = '6046187032954494790285015739939617914882059723833462648323979853562951' tf = logical 0 substr = '5926535897932384626433832795028841971693993751058209749445923078164062' rev = '2604618703295449479028501573993961791488205972383346264832397985356295' tf = logical 0 substr = '9265358979323846264338327950288419716939937510582097494459230781640628' rev = '8260461870329544947902850157399396179148820597238334626483239798535629' tf = logical 0 substr = '2653589793238462643383279502884197169399375105820974944592307816406286' rev = '6826046187032954494790285015739939617914882059723833462648323979853562' tf = logical 0 len = 69 substr = '3.1415926535897932384626433832795028841971693993751058209749445923078' rev = '8703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.14159265358979323846264338327950288419716939937510582097494459230781' rev = '18703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '141592653589793238462643383279502884197169399375105820974944592307816' rev = '618703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '415926535897932384626433832795028841971693993751058209749445923078164' rev = '461870329544947902850157399396179148820597238334626483239798535629514' tf = logical 0 substr = '159265358979323846264338327950288419716939937510582097494459230781640' rev = '046187032954494790285015739939617914882059723833462648323979853562951' tf = logical 0 substr = '592653589793238462643383279502884197169399375105820974944592307816406' rev = '604618703295449479028501573993961791488205972383346264832397985356295' tf = logical 0 substr = '926535897932384626433832795028841971693993751058209749445923078164062' rev = '260461870329544947902850157399396179148820597238334626483239798535629' tf = logical 0 substr = '265358979323846264338327950288419716939937510582097494459230781640628' rev = '826046187032954494790285015739939617914882059723833462648323979853562' tf = logical 0 substr = '653589793238462643383279502884197169399375105820974944592307816406286' rev = '682604618703295449479028501573993961791488205972383346264832397985356' tf = logical 0 len = 68 substr = '3.141592653589793238462643383279502884197169399375105820974944592307' rev = '703295449479028501573993961791488205972383346264832397985356295141.3' tf = logical 0 substr = '.1415926535897932384626433832795028841971693993751058209749445923078' rev = '8703295449479028501573993961791488205972383346264832397985356295141.' tf = logical 0 substr = '14159265358979323846264338327950288419716939937510582097494459230781' rev = '18703295449479028501573993961791488205972383346264832397985356295141' tf = logical 0 substr = '41592653589793238462643383279502884197169399375105820974944592307816' rev = '618703295449479028501...

3   Pass
a = 'truly I say: able was I ere I saw elba, but that is another story'; p = 'able was I ere I saw elba'; assert(isequal(p,pal(a)));

b = 0×0 empty cell array len = 65 substr = 'truly I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 len = 64 substr = 'truly I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 len = 63 substr = 'truly I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 len = 62 substr = 'truly I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 len = 61 substr = 'truly I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 len = 60 substr = 'truly I say: able was I ere I saw elba, but that is another ' rev = ' rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 substr = ' I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I ' tf = logical 0 len = 59 substr = 'truly I say: able was I ere I saw elba, but that is another' rev = 'rehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another ' rev = ' rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 substr = ' I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I ' tf = logical 0 substr = 'I say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas I' tf = logical 0 len = 58 substr = 'truly I say: able was I ere I saw elba, but that is anothe' rev = 'ehtona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is another' rev = 'rehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another ' rev = ' rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 substr = ' I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I ' tf = logical 0 substr = 'I say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas I' tf = logical 0 substr = ' say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas ' tf = logical 0 len = 57 substr = 'truly I say: able was I ere I saw elba, but that is anoth' rev = 'htona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is anothe' rev = 'ehtona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is another' rev = 'rehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another ' rev = ' rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 substr = ' I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I ' tf = logical 0 substr = 'I say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas I' tf = logical 0 substr = ' say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas ' tf = logical 0 substr = 'say: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :yas' tf = logical 0 len = 56 substr = 'truly I say: able was I ere I saw elba, but that is anot' rev = 'tona si taht tub ,able was I ere I saw elba :yas I ylurt' tf = logical 0 substr = 'ruly I say: able was I ere I saw elba, but that is anoth' rev = 'htona si taht tub ,able was I ere I saw elba :yas I ylur' tf = logical 0 substr = 'uly I say: able was I ere I saw elba, but that is anothe' rev = 'ehtona si taht tub ,able was I ere I saw elba :yas I ylu' tf = logical 0 substr = 'ly I say: able was I ere I saw elba, but that is another' rev = 'rehtona si taht tub ,able was I ere I saw elba :yas I yl' tf = logical 0 substr = 'y I say: able was I ere I saw elba, but that is another ' rev = ' rehtona si taht tub ,able was I ere I saw elba :yas I y' tf = logical 0 substr = ' I say: able was I ere I saw elba, but that is another s' rev = 's rehtona si taht tub ,able was I ere I saw elba :yas I ' tf = logical 0 substr = 'I say: able was I ere I saw elba, but that is another st' rev = 'ts rehtona si taht tub ,able was I ere I saw elba :yas I' tf = logical 0 substr = ' say: able was I ere I saw elba, but that is another sto' rev = 'ots rehtona si taht tub ,able was I ere I saw elba :yas ' tf = logical 0 substr = 'say: able was I ere I saw elba, but that is another stor' rev = 'rots rehtona si taht tub ,able was I ere I saw elba :yas' tf = logical 0 substr = 'ay: able was I ere I saw elba, but that is another story' rev = 'yrots rehtona si taht tub ,able was I ere I saw elba :ya' tf = logical 0 len = 55 substr = 'truly I say: able was I ere I saw elba, but ...