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

Solution 327224

Submitted on 1 Oct 2013

Incorrect

326Size
Leading solution size is 2223.
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
Fail
 
%%
% test cases
randn('seed',0);
rand('seed',0);
N=randi([1000 4000],50,1);
S=randi([1,50],50,1);
Boards=arrayfun(@(s)convn(randn(100),ones(s)/s^2,'same'),S,'uni',0);
FLAGSLEFT=0;
DOPLOT=false;
tic;
for board=1:50
 B=Boards{board};
 sB=sort(B(:));
 B=double(B>sB(round(numel(sB)*.9)));
 n=N(board);
 path=capture_the_flag(B,n);
 assert(size(path,1)<=n,'too many steps');
 assert(all(sum(abs(diff([1,1;path])),2)<=1),'no jumping allowed');
 if DOPLOT
    imagesc(B);
    hold on;
    plot(path(:,2),path(:,1),'y-');
    hold off;
    axis equal;
    axis off;
    set(gcf,'color',0*[1 1 1]);
    colormap(.5*gray);
    drawnow;
 end
 B(1)=0;
 B((path-1)*[1;size(B,1)]+1)=0;
 fprintf('test %d; left %d flags\n',board,nnz(B));
 FLAGSLEFT=FLAGSLEFT+nnz(B);
end
toc;
assignin('caller','score',10000);
assert(FLAGSLEFT<=10000,sprintf('Left %d flags',FLAGSLEFT));
assignin('caller','score',FLAGSLEFT);
Error: Out of memory. Type HELP MEMORY for your options.