Diffing "GFD5.1a" and "GFD5.1b"

Title: GFD5.1a GFD5.1b
Author: Francois Glineur Francois Glineur
Submitted: 2000-03-24 04:51:35 UTC 2000-03-24 04:57:50 UTC
Status: Passed Passed
Score: 51683.3 51683.5
Result: 99.9942 99.9942
CPU Time: 13.289 13.459
Code:
function Sequence = GFD4(Segments) % MARCHE ENCORE ?

[nSegs, lSegs] = size(Segments);

[SortedHash Order]  = sort(Segments * randn(lSegs,1))  ;
Segments = Segments(Order(diff([SortedHash ; 0]) ~= 0), :);
[nSegs, lSegs] = size(Segments);

theSegments = cell(nSegs, 1);
theSegs = 1:nSegs;
for index = theSegs,
   theSegments{index} = Segments(index, :);
end
copySegments = theSegments;

matchLength = lSegs-1;
while matchLength > 0
   Segments(:, 1) = [];
   for leftSeg = theSegs
      Match = find(strncmp(Segments(leftSeg, :), copySegments, matchLength));
      if Match
         Select = Match(1);
         rightSeg = theSegs(Select);
         if rightSeg == leftSeg 
            if length(Match) > 1 % Rare case
               temp = Match(Match ~= Select);
               Select = temp(1);
               rightSeg = theSegs(Select); 
               
               theSegments{rightSeg} = [theSegments{leftSeg} theSegments{rightSeg}(1+matchLength:end)];
               i = find(theSegs == leftSeg);
               theSegs(i) = [];
               if length(theSegs) == 1 
                  Sequence = [theSegments{theSegs}];
                  return;
                  matchLength = 1;
                  break;
               end
               copySegments(Select) = copySegments(i);
               copySegments(i) = [];
               end
         else
            theSegments{rightSeg} = [theSegments{leftSeg} theSegments{rightSeg}(1+matchLength:end)];
            i = find(theSegs == leftSeg);
            theSegs(i) = [];
            if length(theSegs) == 1 
               Sequence = [theSegments{theSegs}];
               return;
            end
         else
            theSegments{rightSeg} = [theSegments{leftSeg} theSegments{rightSeg}(1+matchLength:end)];
            i = find(theSegs == leftSeg);
            theSegs(i) = [];
            if length(theSegs) == 1 
               matchLength = 1;
               break;
            end
            copySegments(Select) = copySegments(i);
            copySegments(i) = [];
         end
      end
   end
   matchLength = matchLength - 1;
end
Sequence = [theSegments{theSegs}];