Cody

# Problem 2055. Create numeric palindromes and their square roots

Solution 370761

Submitted on 16 Dec 2013 by J.R.! Menzinger
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
%% n=3; [p,r]=palinroot(n); y_correct=[1 0 0 0 0; 1 2 1 0 0; 1 2 3 2 1]; z_correct=[1 0 0; 1 1 0; 1 1 1]; assert(isequal(p,y_correct)) assert(isequal(r,z_correct))

ans = 1 0 0 0 0 ans = 1 0 0 0 0 1 2 1 0 0 ans = 1 0 0 0 0 1 2 1 0 0 1 2 3 2 1

2   Pass
%% n=9; [p,r]=palinroot(n); rr=1; for s1=2:n rr(s1)=rr(s1-1)*10+1; end rr=num2str(rr','%.0f'); z_correct=tril(fliplr(rr)-'0'); pp=zeros(n,n*2-1); for s=1:n p1=1:s; p2=fliplr(p1); st=deal([p1,p2(2:end)]); pp(s,1:numel(st))=st; end y_correct=pp; assert(isequal(p,y_correct)) assert(isequal(r,z_correct))

ans = Columns 1 through 16 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 17 0 ans = Columns 1 through 16 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 Column 17 0 0 ans = Columns 1 through 16 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 0 0 0 Column 17 0 0 0 ans = Columns 1 through 16 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 0 0 0 0 Column 17 0 0 0 0 ans = Columns 1 through 16 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 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0 1 2 3 4 5 6 5 4 3 2 1 0 0 0 0 0 1 2 3 4 5 6 7 6 5 4 3 2 1 0 0 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 Column 17 0 0 0 0 0 0 0 0 1

3   Pass
%% n=5; [p,r]=palinroot(n); rr=1; for s1=2:n rr(s1)=rr(s1-1)*10+1; end rr=num2str(rr','%.0f'); z_correct=tril(fliplr(rr)-'0'); pp=zeros(n,n*2-1); for s=1:n p1=1:s; p2=fliplr(p1); st=deal([p1,p2(2:end)]); pp(s,1:numel(st))=st; end y_correct=pp; assert(isequal(p,y_correct)) assert(isequal(r,z_correct))

ans = 1 0 0 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 1 2 3 4 3 2 1 0 0 ans = 1 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 1 2 3 4 3 2 1 0 0 1 2 3 4 5 4 3 2 1

4   Pass
%% n=7; [p,r]=palinroot(n); rr=1; for s1=2:n rr(s1)=rr(s1-1)*10+1; end rr=num2str(rr','%.0f'); z_correct=tril(fliplr(rr)-'0'); pp=zeros(n,n*2-1); for s=1:n p1=1:s; p2=fliplr(p1); st=deal([p1,p2(2:end)]); pp(s,1:numel(st))=st; end y_correct=pp; assert(isequal(p,y_correct)) assert(isequal(r,z_correct))

ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 0 1 2 3 4 5 4 3 2 1 0 0 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 0 1 2 3 4 5 4 3 2 1 0 0 0 0 1 2 3 4 5 6 5 4 3 2 1 0 0 ans = 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 0 0 0 0 0 0 0 0 0 0 1 2 3 2 1 0 0 0 0 0 0 0 0 1 2 3 4 3 2 1 0 0 0 0 0 0 1 2 3 4 5 4 3 2 1 0 0 0 0 1 2 3 4 5 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 6 5 4 3 2 1