Prev     Next
Turn the English into Code

group...
       Initialize:     group = 1:m;
       Invariant:     Cable may be added to solution iff group(cables(i,1)) ~= group(cables(i,2))
redundancy(cables(i,:))...
       Prototype:    ---    function r = redundant(cable);
       Return value:    ---    if group(cable(1)) ~= group(cable(2)) r = 0; else r = 1; end
       Global:    ---    group
addcable(cables(i,:))...
       Prototype:    ---    function addcable(cable);
       Set constants:    ---    g1 = group(cable(1)); g2 = group(cable(2))
       Do for every i:    ---    if group(i) == g2 group(i) = g1; end
       Add cable to solution:    ---    solution = [solution ; cable];
       Global:    ---    group, solution