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 1.284096 seconds.
|
2 | 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.093368 seconds.
|
3 | 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.315770 seconds.
|
4 | 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 =
210.0000
|
Get the elements of diagonal and antidiagonal for any m-by-n matrix
267 Solvers
Find nearest prime number less than input number
268 Solvers
228 Solvers
130 Solvers
Calculate Amount of Cake Frosting
7479 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!