Cody

Problem 172. Test if a Number is a Palindrome without using any String Operations

Solution 487622

Submitted on 18 Aug 2014 by Abdullah Caliskan
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
%% x = 122131221; y_correct = true; assert( isequal(isNumPalindrome(x),y_correct) && isempty(regexp(evalc('type isNumPalindrome'),'(str|printf|eval|flip|dec2base)')) )

XX = [] s = 122131221 XX = 0 X = 122131221 s = 122131221 XX = 0 0 X = 122131221 s = 22131221 XX = 0 0 1 X = 22131221 s = 2131221 XX = 0 0 1 2 X = 2131221 s = 131221 XX = 0 0 1 2 2 X = 131221 s = 31221 XX = 0 0 1 2 2 1 X = 31221 s = 1221 XX = 0 0 1 2 2 1 3 X = 1221 s = 221 XX = 0 0 1 2 2 1 3 1 X = 221 s = 21 XX = 0 0 1 2 2 1 3 1 2 X = 21 s = 1 XX = 0 0 1 2 2 1 3 1 2 2 X = 1 s = 0 XX = 0 0 1 2 2 1 3 1 2 2 1 X = 0 XX = 1 2 2 1 3 1 2 2 1 [Warning: Integer operands are required for colon operator when used as index] [> In isNumPalindrome at 9 In verifyCode>evaluateCode at 238 In verifyCode at 43 In fevalJSON at 14] [Warning: Integer operands are required for colon operator when used as index] [> In isNumPalindrome at 9 In verifyCode>evaluateCode at 238 In verifyCode at 43 In fevalJSON at 14] ans = 1

2   Pass
%% x = 1221; y_correct = true; assert( isequal(isNumPalindrome(x),y_correct) && isempty(regexp(evalc('type isNumPalindrome'),'(str|printf|eval|flip|dec2base)')) )

XX = [] s = 1221 XX = 0 X = 1221 s = 1221 XX = 0 0 X = 1221 s = 1221 XX = 0 0 0 X = 1221 s = 1221 XX = 0 0 0 0 X = 1221 s = 1221 XX = 0 0 0 0 0 X = 1221 s = 1221 XX = 0 0 0 0 0 0 X = 1221 s = 1221 XX = 0 0 0 0 0 0 0 X = 1221 s = 221 XX = 0 0 0 0 0 0 0 1 X = 221 s = 21 XX = 0 0 0 0 0 0 0 1 2 X = 21 s = 1 XX = 0 0 0 0 0 0 0 1 2 2 X = 1 s = 0 XX = 0 0 0 0 0 0 0 1 2 2 1 X = 0 XX = 1 2 2 1 ans = 1

3   Pass
%% x = 12345; y_correct = false; assert( isequal(isNumPalindrome(x),y_correct) && isempty(regexp(evalc('type isNumPalindrome'),'(str|printf|eval|flip|dec2base)')) )

XX = [] s = 12345 XX = 0 X = 12345 s = 12345 XX = 0 0 X = 12345 s = 12345 XX = 0 0 0 X = 12345 s = 12345 XX = 0 0 0 0 X = 12345 s = 12345 XX = 0 0 0 0 0 X = 12345 s = 12345 XX = 0 0 0 0 0 0 X = 12345 s = 2345 XX = 0 0 0 0 0 0 1 X = 2345 s = 345 XX = 0 0 0 0 0 0 1 2 X = 345 s = 45 XX = 0 0 0 0 0 0 1 2 3 X = 45 s = 5 XX = 0 0 0 0 0 0 1 2 3 4 X = 5 s = 0 XX = 0 0 0 0 0 0 1 2 3 4 5 X = 0 XX = 1 2 3 4 5 [Warning: Integer operands are required for colon operator when used as index] [> In isNumPalindrome at 9 In verifyCode>evaluateCode at 238 In verifyCode at 43 In fevalJSON at 14] [Warning: Integer operands are required for colon operator when used as index] [> In isNumPalindrome at 9 In verifyCode>evaluateCode at 238 In verifyCode at 43 In fevalJSON at 14] ans = 0

4   Pass
%% x = 9849; y_correct = false; assert( isequal(isNumPalindrome(x),y_correct) && isempty(regexp(evalc('type isNumPalindrome'),'(str|printf|eval|flip|dec2base)')) )

XX = [] s = 9849 XX = 0 X = 9849 s = 9849 XX = 0 0 X = 9849 s = 9849 XX = 0 0 0 X = 9849 s = 9849 XX = 0 0 0 0 X = 9849 s = 9849 XX = 0 0 0 0 0 X = 9849 s = 9849 XX = 0 0 0 0 0 0 X = 9849 s = 9849 XX = 0 0 0 0 0 0 0 X = 9849 s = 849 XX = 0 0 0 0 0 0 0 9 X = 849 s = 49 XX = 0 0 0 0 0 0 0 9 8 X = 49 s = 9 XX = 0 0 0 0 0 0 0 9 8 4 X = 9 s = 0 XX = 0 0 0 0 0 0 0 9 8 4 9 X = 0 XX = 9 8 4 9 ans = 0

Suggested Problems

More from this Author56

Community Treasure Hunt

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

Start Hunting!