Cody

Solution 1841988

Submitted on 7 Jun 2019
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
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 1-Seaman r=[0 2 2 3 1 1 1 1 2 2 5 0]'; c=[0 1 0 1 1 2 6 0 5 0 4 0]; m(2,2)=1; m(2,6)=1; m(4,9)=3; %tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); %tt=tz+cputime-time0 tt=cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 0.0800 Elapsed time is 0.092572 seconds.

2   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 2-Petty Officer r=[0 0 1 4 1 3 3 3 3 2 0 0]'; c=[0 2 3 2 0 5 0 4 0 2 2 0]; m(5,4)=3; m(6,11)=3; m(9,8)=0; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 2.7400 Elapsed time is 2.495950 seconds.

3   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 3-Ensign r=[0 3 0 4 1 0 0 1 2 1 8 0]'; c=[0 5 1 1 3 1 1 1 1 3 3 0]; m(4,7)=1; m(4,11)=3; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 9847379391150x17 (1247267.8GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test3 (line 14) b=solve_battleship(m,r,c);

4   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 4-Captain r=[0 1 2 2 2 2 5 0 5 0 1 0]'; c=[0 5 0 0 0 2 1 4 2 1 5 0]; m(4,8)=0; m(7,10)=4; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 353697121050x18 (47434.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test4 (line 14) b=solve_battleship(m,r,c);

5   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 5-Commodore r=[0 1 1 5 0 3 1 3 2 1 3 0]'; c=[0 2 2 1 0 2 1 6 0 5 1 0]; m(6,4)=1; m(6,8)=0; m(7,10)=3; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 6499270398159x17 (823196.7GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test5 (line 15) b=solve_battleship(m,r,c);

6   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % Games August 2013 6-Admiral r=[0 5 1 4 2 3 1 1 0 3 0 0]'; c=[0 4 0 1 2 4 2 1 1 5 0 0]; m(5,2)=1; m(10,7)=6; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 991493848554x16 (118195.3GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test6 (line 14) b=solve_battleship(m,r,c);

7   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 1-Seaman r=[0 1 1 1 1 2 3 3 3 1 4 0]'; c=[0 3 2 0 1 6 0 3 1 4 0 0]; m(2,3)=1; m(8,5)=1; m(7,8)=6; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 2.7400 Elapsed time is 0.006549 seconds.

8   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 2-Petty r=[0 2 2 2 3 2 0 0 7 0 2 0]'; c=[0 2 5 1 4 1 4 0 2 1 0 0]; m(3,3)=3; m(5,7)=1; m(9,4)=0; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 3.3000 Elapsed time is 0.565150 seconds.

9   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 3-Ensign r=[0 3 0 0 2 4 3 2 1 4 1 0]'; c=[0 2 2 5 2 3 0 3 0 2 1 0]; m(7,2)=1; m(7,4)=3; m(9,8)=0; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 2310789600x13 (223.8GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test9 (line 15) b=solve_battleship(m,r,c);

10   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 4-Captain r=[0 2 0 2 2 2 3 2 3 0 4 0]'; c=[0 4 0 3 1 3 1 4 0 1 3 0]; m(8,2)=2; m(2,5)=5; m(11,7)=4; m(8,11)=6; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 5.0200 Elapsed time is 1.719142 seconds.

11   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 5-Commodore r=[0 3 2 3 1 1 1 3 3 2 1 0]'; c=[0 1 2 4 1 4 1 1 0 5 1 0]; m(2,10)=5; m(8,4)=6; m(8,6)=5; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 600805296x11 (49.2GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test11 (line 15) b=solve_battleship(m,r,c);

12   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % December 2013 6-Admiral r=[0 5 1 0 3 0 1 5 2 3 0 0]'; c=[0 0 4 2 5 2 1 2 1 1 2 0]; m(2,10)=0; m(8,7)=0; m(10,5)=1; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Maximum variable size allowed by the program is exceeded. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test12 (line 15) b=solve_battleship(m,r,c);

13   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 1-Seaman r=[0 1 1 2 4 1 0 2 2 5 2 0]'; c=[0 1 1 1 1 4 0 7 0 2 3 0]; m(2,8)=0; m(8,3)=1; m(9,6)=0; m(5,11)=6; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 5.0300 Elapsed time is 0.005118 seconds.

14   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 2-Petty r=[0 5 1 4 1 0 5 1 2 1 0 0]'; c=[0 2 3 3 2 0 5 0 3 1 1 0]; m(9,2)=1; m(2,7)=0; m(3,9)=1; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 5.0300 Elapsed time is 0.003385 seconds.

15   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 3-Ensign r=[0 3 0 2 3 1 1 2 2 2 4 0]'; c=[0 1 1 0 6 1 4 0 3 1 3 0]; m(4,3)=0; m(5,6)=4; m(7,9)=6; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 5.0400 Elapsed time is 0.007572 seconds.

16   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 4-Captain r=[0 0 6 0 2 2 4 1 3 2 0 0]'; c=[0 3 1 3 1 2 2 2 2 0 4 0]; m(5,2)=0; m(9,4)=0; m(3,5)=4; m(6,11)=2; m(8,11)=3; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 9669554100x14 (1008.6GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test16 (line 17) b=solve_battleship(m,r,c);

17   Fail
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 5-Commodore % r=[0 5 2 1 1 7 1 2 0 0 1 0]'; c=[0 2 3 1 2 1 3 1 2 0 5 0]; m(8,2)=1; m(5,11)=2; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

Error using zeros Requested 6499270398159x17 (823196.7GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in nchoosek>combs (line 164) P = zeros(total, k, 'like', v); Error in nchoosek (line 123) c = combs(v,k); Error in solve_battleship (line 48) j3 = nchoosek(j1,j2); Error in Test17 (line 14) b=solve_battleship(m,r,c);

18   Pass
global tt m=zeros(12); m(2:end-1,2:end-1)=7; % September 2013 6-Admiral % Solved with with Bship HV .10 % solved recur .023 r=[0 0 2 4 1 4 1 0 2 0 6 0]'; c=[0 3 1 3 1 3 2 1 2 1 3 0]; m(3,2)=0; m(4,5)=4; m(9,9)=5; tz=tt; % anti-cheat tic time0=cputime; b=solve_battleship(m,r,c); tt=tz+cputime-time0 %toc b(b>1)=0; b(b<0)=0; br=sum(b,2); bc=sum(b); assert(isequal(r,br)) assert(isequal(c,bc)) % find battleship,cruisers,destroyers,subs % conv2 to locate pieces % bsh,bsv % ch,cv,dh,dv,s mconvsub=conv2(b,[2 2 2;2 1 2;2 2 2],'same'); subs_ptr=find(mconvsub==1); % Isolated valid subs assert(size(subs_ptr,1)==4) % Qty of subs_ptr must be 4 mconvBH=conv2(b,[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); mconvBV=conv2(b',[5 5 5 5 5 5;5 1 1 1 1 5;5 5 5 5 5 5],'same'); BS_ptr=[find(mconvBH==4);find(mconvBV==4)]; assert(size(BS_ptr,1)==1) % Qty of BS_ptr must be 1 mconvCH=conv2(b,[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); mconvCV=conv2(b',[5 5 5 5 5;5 1 1 1 5;5 5 5 5 5],'same'); CS_ptr=[find(mconvCH==3);find(mconvCV==3)]; assert(size(CS_ptr,1)==2) % Qty of CS_ptr must be 2 mconvDH=conv2(b,[5 5 5 5;5 1 1 5;5 5 5 5],'same'); mconvDV=conv2(b',[5 5 5 5;5 1 1 5;5 5 5 5],'same'); DS_ptr=[find(mconvDH==2);find(mconvDV==2)]; assert(size(DS_ptr,1)==3) % Qty of DS_ptr must be 3 toc

tt = 7.0200 Elapsed time is 1.891683 seconds.

19   Pass
global tt tt assignin('caller','score',min(2000,floor(1000*tt)));

tt = 7.0200