Code covered by the BSD License  

Highlights from
MATLAB Contest - Gene Splicing

from MATLAB Contest - Gene Splicing by The MATLAB Contest Team
All the files needed to develop and score an entry for the MATLABĀ® Programming Contest.

doMoves(seq,moves,budget)
function seq = doMoves(seq,moves,budget)

% Copyright 2007 The MathWorks, Inc.

if size(moves,1)>budget
    moves = moves(1:budget,:);
end
if size(moves,2)~=4 || ~isnumeric(moves) || ~isreal(moves) || any(moves(:)-round(moves(:)))
    error('MOVES must be a numeric and real matrix with 4 columns')
end

n = numel(seq);
moves(:,1) = max(1,min(n,moves(:,1)));
moves(:,2) = max(1,min(n-moves(:,1)+1,moves(:,2)));
moves(:,3) = max(1,min(n-moves(:,1)+1,moves(:,3)));
moves(:,4) = moves(:,4) ~= 0;
for i =1:size(moves,1)
    le = moves(i,1);
    ai = moves(i,2);
    bi = moves(i,3);
    f = moves(i,4);
    if f
        if ai>bi
            seq = seq([1:bi-1 ai+le-1:-1:ai bi:ai-1 ai+le:end]);
        else
            seq = seq([1:ai-1 ai+le:bi+le-1 ai+le-1:-1:ai bi+le:end]);
        end
    else
        if ai>bi
            seq = seq([1:bi-1 ai:ai+le-1 bi:ai-1 ai+le:end]);
        else
            seq = seq([1:ai-1 ai+le:bi+le-1 ai:ai+le-1 bi+le:end]);
        end
    end
end

Contact us at files@mathworks.com