Cody

# Problem 2085. Sudoku Solver - Standard 9x9

Solution 2171030

Submitted on 23 Mar 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
% 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.032387 seconds.

2   Fail
% 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)

Undefined function 'sudoku' for input arguments of type 'double'. Error in sudoku_solver (line 13) X = sudoku(X); Error in Test2 (line 10) mout=sudoku_solver(m)

3   Fail
% 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)

Undefined function 'sudoku' for input arguments of type 'double'. Error in sudoku_solver (line 13) X = sudoku(X); Error in Test3 (line 10) mout=sudoku_solver(m)

4   Fail
% 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)));

Undefined function 'sudoku' for input arguments of type 'double'. Error in sudoku_solver (line 13) X = sudoku(X); Error in Test4 (line 12) mout=sudoku_solver(m)