Cody

Solution 357549

Submitted on 22 Nov 2013 by Alfonso Nieto-Castanon
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',2000);
2   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.3300 Elapsed time is 0.321932 seconds.
3   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 = 0.3600 Elapsed time is 0.032873 seconds.
4   Pass
%% 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
tt = 0.7000 Elapsed time is 0.331886 seconds.
5   Pass
%% 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
tt = 0.8800 Elapsed time is 0.179900 seconds.
6   Pass
%% 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
tt = 1.3500 Elapsed time is 0.450733 seconds.
7   Pass
%% 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
tt = 1.4200 Elapsed time is 0.068675 seconds.
8   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 = 1.5000 Elapsed time is 0.080688 seconds.
9   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 = 2.1200 Elapsed time is 0.599258 seconds.
10   Pass
%% 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
tt = 2.6400 Elapsed time is 0.511155 seconds.
11   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 = 2.6700 Elapsed time is 0.027965 seconds.
12   Pass
%% 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
tt = 3.8000 Elapsed time is 1.102435 seconds.
13   Pass
%% 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
tt = 6.6900 Elapsed time is 2.804943 seconds.
14   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 = 8.8200 Elapsed time is 2.059732 seconds.
15   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 = 8.8300 Elapsed time is 0.004737 seconds.
16   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 = 9.1000 Elapsed time is 0.263315 seconds.
17   Pass
%% 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
tt = 9.4200 Elapsed time is 0.307801 seconds.
18   Pass
%% 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
tt = 9.8400 Elapsed time is 0.411054 seconds.
19   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 = 9.9800 Elapsed time is 0.130388 seconds.
20   Pass
%% global tt tt assignin('caller','score',min(2000,floor(1000*tt)));
tt = 9.9800