Cody

Solution 419712

Submitted on 18 Mar 2014 by mmmriva
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
assignin('caller','score',500);

2   Pass
%% % Test 1 mstr=['012300007'; '040600010'; '078900020'; '000000040'; '100000002'; '060000000'; '080001230'; '090004060'; '300007890']; % convert string to array m=zeros(9); for i=1:9 m(i,:)=mstr(i,:)-'0' ; end tic mout=sudoku_solver(m) toc valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); assert(valid==1) ptr=find(m>0); valid2=isequal(m(ptr),mout(ptr)); assert(valid2==1)

mout = 9 1 2 3 4 8 6 5 7 5 4 3 6 7 2 9 1 8 6 7 8 9 1 5 4 2 3 8 2 7 1 5 9 3 4 6 1 3 9 4 8 6 5 7 2 4 6 5 7 2 3 1 8 9 7 8 6 5 9 1 2 3 4 2 9 1 8 3 4 7 6 5 3 5 4 2 6 7 8 9 1 Elapsed time is 0.057138 seconds.

3   Pass
%% % Test 2 mstr=['000004500'; '000003600'; '432008700'; '867000000'; '000000000'; '000000417'; '001900854'; '006400000'; '003700000']; % convert string to array m=zeros(9); for i=1:9 m(i,:)=mstr(i,:)-'0' ; end tic mout=sudoku_solver(m) toc valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); assert(valid==1) ptr=find(m>0); valid2=isequal(m(ptr),mout(ptr)); assert(valid2==1)

mout = 6 1 9 2 7 4 5 3 8 7 5 8 1 9 3 6 4 2 4 3 2 6 5 8 7 9 1 8 6 7 3 4 1 9 2 5 1 9 4 5 2 7 3 8 6 3 2 5 8 6 9 4 1 7 2 7 1 9 3 6 8 5 4 9 8 6 4 1 5 2 7 3 5 4 3 7 8 2 1 6 9 Elapsed time is 0.016470 seconds.

4   Pass
%% % Test 3 mstr=['120034000'; '000000056'; '000200000'; '007800002'; '600000001'; '500006300'; '000008000'; '340000000'; '000560078']; % convert string to array m=zeros(9); for i=1:9 m(i,:)=mstr(i,:)-'0' ; end tic mout=sudoku_solver(m) toc valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); assert(valid==1) ptr=find(m>0); valid2=isequal(m(ptr),mout(ptr)); assert(valid2==1)

mout = 1 2 5 6 3 4 8 9 7 4 7 3 1 8 9 2 5 6 8 6 9 2 5 7 1 3 4 9 3 7 8 4 1 5 6 2 6 8 2 3 9 5 7 4 1 5 1 4 7 2 6 3 8 9 7 5 6 4 1 8 9 2 3 3 4 8 9 7 2 6 1 5 2 9 1 5 6 3 4 7 8 Elapsed time is 0.018426 seconds.

5   Pass
%% % Timed Test on a Hard Sudoku % Non-Valid answer creates a Max score but not a fail % Hard Sudoku mstr=['005700009'; '030090010'; '100005300'; '600004700'; '040010050'; '002500001'; '004600002'; '080020040'; '200008600']; % convert string to array m=zeros(9); for i=1:9 m(i,:)=mstr(i,:)-'0' ; end time0=cputime; mout=sudoku_solver(m) etime=(cputime-time0)*1000 % msec valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); ptr=find(m>0); valid2=isequal(m(ptr),mout(ptr)); % Not Asserting for Valid answer if ~valid,etime=500;end if ~valid2,etime=500;end assignin('caller','score',min(500,floor(etime)));

mout = 4 6 5 7 3 1 2 8 9 7 3 8 4 9 2 5 1 6 1 2 9 8 6 5 3 7 4 6 5 1 9 8 4 7 2 3 3 4 7 2 1 6 9 5 8 8 9 2 5 7 3 4 6 1 9 1 4 6 5 7 8 3 2 5 8 6 3 2 9 1 4 7 2 7 3 1 4 8 6 9 5 etime = 30.0000