Code covered by the BSD License  

Highlights from
MATLAB Contest - Army Ants

from MATLAB Contest - Army Ants by The MATLAB Contest Team
All the files needed to develop and score an entry for the MATLABĀ® Programming Contest.

grade(main,foodStart,red,black,food)
function score = grade(main,foodStart,red,black,food)

% Copyright 2008 The MathWorks, Inc.

% Add up distance of all food units to the closest home.
f = nonzeros(food);
[yf,xf] = find(food);
[ym,xm] = find(main==-1);
score = min(abs(bsxfun(@minus,(xf+1i*yf).',xm+1i*ym)),[],1)*f;
end

Contact us at files@mathworks.com