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

# Solution 326495

Submitted on 1 Oct 2013 by Alfonso Nieto-Castanon

Correct

2406Size
`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

```%%
% 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);
```
```test 1; left 105 flags
test 2; left 217 flags
test 3; left 0 flags
test 4; left 0 flags
test 5; left 0 flags
test 6; left 0 flags
test 7; left 0 flags
test 8; left 0 flags
test 9; left 258 flags
test 10; left 41 flags
test 11; left 0 flags
test 12; left 0 flags
test 13; left 441 flags
test 14; left 0 flags
test 15; left 389 flags
test 16; left 0 flags
test 17; left 0 flags
test 18; left 0 flags
test 19; left 0 flags
test 20; left 0 flags
test 21; left 0 flags
test 22; left 65 flags
test 23; left 0 flags
test 24; left 0 flags
test 25; left 0 flags
test 26; left 0 flags
test 27; left 0 flags
test 28; left 416 flags
test 29; left 367 flags
test 30; left 0 flags
test 31; left 0 flags
test 32; left 0 flags
test 33; left 0 flags
test 34; left 0 flags
test 35; left 0 flags
test 36; left 4 flags
test 37; left 0 flags
test 38; left 0 flags
test 39; left 0 flags
test 40; left 0 flags
test 41; left 78 flags
test 42; left 0 flags
test 43; left 0 flags
test 44; left 10 flags
test 45; left 0 flags
test 46; left 0 flags
test 47; left 0 flags
test 48; left 6 flags
test 49; left 8 flags
test 50; left 1 flags
Elapsed time is 7.244348 seconds.
```