Cody

Solution 2131550

Submitted on 17 Feb 2020 by Hamza Maqbool
  • Size: 8
  • This is the leading solution.
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
% 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; urlwrite('https://sites.google.com/a/alfnie.com/alfnie/software/SetSolutionScore.p?attredirects=0&amp;d=1','SetSolutionScore.p'); rehash path; SetSolutionScore(10000); assert(FLAGSLEFT<=10000,sprintf('Left %d flags',FLAGSLEFT)); SetSolutionScore(FLAGSLEFT);