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.4200
Elapsed time is 0.437518 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.4300
Elapsed time is 0.007245 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.135289 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 =
    1.1300
Elapsed time is 0.564857 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.8000
Elapsed time is 0.671554 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.8200
Elapsed time is 0.016353 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 =
    2.2000
Elapsed time is 0.382356 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.8000
Elapsed time is 0.595128 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 =
    7.1500
Elapsed time is 4.318094 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 =
    7.1600
Elapsed time is 0.015812 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 =
    8.5600
Elapsed time is 1.384662 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 =
   10.4700
Elapsed time is 1.898763 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 =
   10.4900
Elapsed time is 0.025561 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 =
   10.5000
Elapsed time is 0.014879 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 =
   12.4900
Elapsed time is 1.965960 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 =
   12.6600
Elapsed time is 0.169073 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 =
   12.7700
Elapsed time is 0.109949 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 =
   12.7800
Elapsed time is 0.010013 seconds.
20
Pass
 
%%
global tt
tt
assignin('caller','score',min(2000,floor(1000*tt)));
tt =
   12.7800