Cody

Solution 2161506

Submitted on 16 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   Fail
% 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×27 char array '-48-47-46-45-48-48-48-48-41' '-48-44-48-42-48-48-48-47-48' '-48-41-40-39-48-48-48-46-48' '-48-48-48-48-48-48-48-44-48' '-47-48-48-48-48-48-48-48-46' '-48-42-48-48-48-48-48-48-48' '-48-40-48-48-48-47-46-45-48' '-48-39-48-48-48-44-48-42-48' '-45-48-48-48-48-41-40-39-48' Elapsed time is 0.042455 seconds.

Error using horzcat Dimensions of arrays being concatenated are not consistent. Error in Test1>@(i)all(sum([mout,mout']==i)) (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); Error in Test1 (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout)));

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)

mout = 9×27 char array '-48-48-48-48-48-44-43-48-48' '-48-48-48-48-48-45-42-48-48' '-44-45-46-48-48-40-41-48-48' '-40-42-41-48-48-48-48-48-48' '-48-48-48-48-48-48-48-48-48' '-48-48-48-48-48-48-44-47-41' '-48-48-47-39-48-48-40-43-44' '-48-48-42-44-48-48-48-48-48' '-48-48-45-41-48-48-48-48-48' Elapsed time is 0.004303 seconds.

Error using horzcat Dimensions of arrays being concatenated are not consistent. Error in Test2>@(i)all(sum([mout,mout']==i)) (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); Error in Test2 (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout)));

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)

mout = 9×27 char array '-47-46-48-48-45-44-48-48-48' '-48-48-48-48-48-48-48-43-42' '-48-48-48-46-48-48-48-48-48' '-48-48-41-40-48-48-48-48-46' '-42-48-48-48-48-48-48-48-47' '-43-48-48-48-48-42-45-48-48' '-48-48-48-48-48-40-48-48-48' '-45-44-48-48-48-48-48-48-48' '-48-48-48-43-42-48-48-41-40' Elapsed time is 0.002696 seconds.

Error using horzcat Dimensions of arrays being concatenated are not consistent. Error in Test3>@(i)all(sum([mout,mout']==i)) (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); Error in Test3 (line 13) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout)));

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)));

mout = 9×27 char array '-48-48-43-41-48-48-48-48-39' '-48-45-48-48-39-48-48-47-48' '-47-48-48-48-48-43-45-48-48' '-42-48-48-48-48-44-41-48-48' '-48-44-48-48-47-48-48-43-48' '-48-48-46-43-48-48-48-48-47' '-48-48-44-42-48-48-48-48-46' '-48-40-48-48-46-48-48-44-48' '-46-48-48-48-48-40-42-48-48' etime = 0

Error using horzcat Dimensions of arrays being concatenated are not consistent. Error in Test4>@(i)all(sum([mout,mout']==i)) (line 14) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout))); Error in Test4 (line 14) valid=all(arrayfun(@(i) all(sum([mout mout']==i)),1:length(mout)));