Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Correct

2000Size
Leading solution size is 320.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
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.1400
Elapsed time is 0.334133 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.2800
Elapsed time is 0.139210 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.5700
Elapsed time is 0.280011 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.6700
Elapsed time is 0.091032 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 =
    0.8300
Elapsed time is 0.155351 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.0100
Elapsed time is 0.170638 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.1900
Elapsed time is 0.168417 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 =
    1.5300
Elapsed time is 0.326894 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 =
    4.0300
Elapsed time is 2.394115 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 =
    4.0600
Elapsed time is 0.026665 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 =
    5.0800
Elapsed time is 0.991536 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 =
    5.6000
Elapsed time is 0.510691 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 =
    7.5500
Elapsed time is 1.903751 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 =
    7.6100
Elapsed time is 0.059431 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.5600
Elapsed time is 1.905361 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.5800
Elapsed time is 0.016353 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 =
   10.7500
Elapsed time is 1.159414 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 =
   10.8100
Elapsed time is 0.063472 seconds.
20
Pass
 
%%
global tt
tt
assignin('caller','score',min(2000,floor(1000*tt)));
tt =
   10.8100