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.

findMultiParent(parent,parent2,A)
function [multiParents,nParents] = findMultiParent(parent,parent2,A)

% Find likely secondary parents

n = numel(parent);

multiParents = cell(1,n);
nParents = zeros(1,n);

for i=1:n;
    if parent2(i)
        multiParents{i}(1)=parent2(i);
        % what lines appear in i but not in its parent?
        newlines = A(:,i) & ~A(:,parent2(i));
        % find where these lines last appeared before i
        B = A(newlines,:);
        B(:,i:end)=0;
        for j=1:size(B,1);
            lastAppear = max(find(B(j,:)));
            if lastAppear ~= parent2(i)
                multiParents{i}=[multiParents{i} lastAppear];
            end
        end
        multiParents{i} = unique(multiParents{i});
        nParents(i) = numel(multiParents{i});
    end
    
end


return

Contact us at files@mathworks.com