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

GFD6f

by Francois Glineur

Status: Passed
Results: 99.9961
CPU Time: 10.495
Score: 51681.5
Submitted at: 2000-03-24 16:57:16 UTC
Scored at: 2000-03-24 17:10:34 UTC

Current Rank: 4th
Based on: GFD5.1bj2 (diff)

Comments
Please login or create a profile.
Code
function Sequence = GFD6(Segments)

lSegs = size(Segments, 2);

[SortedHash Order]  = sort(Segments * (1./(2:lSegs+1))')  ;
 	startSegs = Order(diff(cat(1, SortedHash, 0)) ~= 0)';
endSegs = startSegs;

nSegs = length(startSegs);

Description = cell(nSegs, 1);
for index = startSegs
   Description{index} = index;
end

matchLength = lSegs-1; leftSegs = nSegs;
while matchLength > 0
   RandWeight = randn(matchLength, 1);
   LeftHash = Segments(endSegs, lSegs-matchLength+1:end) * RandWeight;
   RightHash = (Segments(startSegs, 1:matchLength) * RandWeight)';
   indexLeft = 1; 
   while indexLeft <= leftSegs 
      Match = findstr(LeftHash(indexLeft), RightHash);
      if Match
         indexRight = Match(1);
         if (indexRight == indexLeft) & (length(Match) > 1) % Rare case, happens e.g. with strvcat('AAA','AAG','AGC')
            indexRight = Match(2); 
         end
         if indexRight ~= indexLeft
            Description{startSegs(indexLeft)} = cat(2, Description{startSegs(indexLeft)}, lSegs-matchLength, Description{startSegs(indexRight)});
            startSegs(indexRight) = startSegs(indexLeft); 
            startSegs(indexLeft) = []; endSegs(indexLeft) = [];
            leftSegs = leftSegs - 1;
            RightHash(indexRight) = RightHash(indexLeft);
            RightHash(indexLeft) = []; LeftHash(indexLeft) = [];
            
            if leftSegs == 1 
               matchLength = 1;
               break;   
            end
         else
            indexLeft = indexLeft + 1;
         end
      else
         indexLeft = indexLeft + 1;
      end
   end
   matchLength = matchLength - 1;
end
if length(startSegs) > 1 % If disjoint segments in the end, we have to merge them !
   for index = 2:length(startSegs)
      Description{startSegs(1)} = [Description{startSegs(1)} lSegs Description{startSegs(index)}];
   end
   startSegs = startSegs(1);
end
Sequence(repmat(cumsum(cat(2, 0, Description{startSegs}(2:2:2*nSegs-2)))', 1, lSegs) + repmat(1:lSegs, nSegs, 1)) = Segments(Description{startSegs}(1:2:2*nSegs-1), :);