No BSD License  

Highlights from
meet the family

image thumbnail
from meet the family by nathan q
Visualisation of a family tree in the programming contest.

findParent(parent,nshare,nULines)
function parent2 = findParent(parent,nshare,nULines)

% For code with a declared parent, find the most likely parent, based on
% number of lines in common

n = numel(parent);
parent2 = parent;

for i=1:n
    if ~parent(i)
        if nULines(i)>0
            fracShare = nshare(i,:)/nULines(i);
            fracShare(i:end)=0;
            [smax,jmax] = max(fracShare);
            if smax>0.5
                parent2(i)=jmax;
            end
        end
    end
end

return

Contact us at files@mathworks.com