Prev     Next
Turn the English into Code

group...
       Initialize:     group = 1:ncities;
       Invariant:     Cable may be added to solution iff
group(cables(i,1)) ~= group(cables(i,2))
causes_cycle(cables(i,:))...
       Prototype:    ---    function result = causes_cycle(cable);
       Return value:    ---    if group(cable(1)) ~= group(cable(2))
   result = 0;
else
   result = 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