Finish 2000-03-27 00:00:00 UTC

withgusto.10

by Don Maszle

Status: Passed
Results: 99.9942
CPU Time: 13.219
Score: 51683.2
Submitted at: 2000-03-24 16:58:45 UTC
Scored at: 2000-03-24 17:15:40 UTC

Current Rank: 13th
Based on: withgusto.9 (diff)
Basis for: withgusto.11 (diff)

Comments
Don Maszle
24 Mar 2000
few changes that is.
Please login or create a profile.
Code
function Sequence = withgusto(Segments) % MARCHE ENCORE ?
%minor changes here....
[nSegs, lSegs] = size(Segments);

[SortedHash Order]  = sort(Segments * randn(lSegs,1))  ;
Segments = Segments(Order(logical([1;diff(SortedHash)~=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} = cat(2,theSegments{leftSeg}, theSegments{rightSeg}(1+matchLength:end));
               i = find(theSegs == leftSeg);
               theSegs(i) = [];
               if length(theSegs) == 1 
                  Sequence = theSegments{theSegs};
                  return;
               end
               copySegments(Select) = copySegments(i);
               copySegments(i) = [];
               end
         else
            theSegments{rightSeg} = cat(2,theSegments{leftSeg}, theSegments{rightSeg}(1+matchLength:end));
            i = find(theSegs == leftSeg);
            theSegs(i) = [];
            if length(theSegs) == 1 
               Sequence = theSegments{theSegs};
               return;
            end
            copySegments(Select) = copySegments(i);
            copySegments(i) = [];
         end
      end
   end
   matchLength = matchLength - 1;
end
Sequence = [theSegments{theSegs}];