Winner Markus (ones 8)

Finish 2007-11-14 12:00:00 UTC

LAST_PLACE_CASH_PRIZE

by Nick Clark

Status: Passed
Results: 181489.23 (cyc: 3)
CPU Time: 0.5073
Score: 18151.0
Submitted at: 2007-11-13 15:50:22 UTC
Scored at: 2007-11-13 19:02:09 UTC

Current Rank: 2637th
Basis for: meat4 (diff)

Comments
Nick Clark
13 Nov 2007
Deliberate attempt to loose badly!
Please login or create a profile.
Code
function moves = solver(sequence,target,budget)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Making the worst score for last place kudos!!!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
moves = ones(0,4);

%--------------------------------------------------------------------------
% First I shift and rotate whole sequence to make worst fit to target
%--------------------------------------------------------------------------
errNorm = zeros(1,length(target));
errFlip = zeros(1,length(target));
errNorm(1) = sum(abs(target-sequence));
errFlip(1) = sum(abs(target-fliplr(sequence)));
for i=2:length(sequence)
    errNorm(i) = sum(abs( target - [sequence(i:end) sequence(1:i-1)] ));
    errFlip(i) = sum(abs( target - fliplr([sequence(i:end) sequence(1:i-1)]) ));
end

errPoint = max(find([errNorm errFlip] == max([errNorm errFlip]))); %finds smallest and if there is an equal minima then the non-flipped version takes precedence
if errPoint > length(sequence) 
    len = length(sequence) - max(find(errFlip == min(errFlip)))+1;
    ai = max(find(errFlip == max(errFlip)));
    bi = 1;
    flip = 0;
    moves(end+1,:) = [len,ai,bi,flip]; %splice in the correct spot
    len = length(sequence);
    ai = 1;
    bi = 1;
    flip = 1;
    moves(end+1,:) = [len,ai,bi,flip]; %flip the whole lot
    sequence = fliplr([sequence(moves(1,2):end) sequence(1:moves(1,2)-1)]);
else
    len = length(sequence) - max(find(errNorm == min(errNorm)))+1;
    ai = max(find(errNorm == max(errNorm)));
    bi = 1;
    flip = 0;
    moves(end+1,:) = [len,ai,bi,flip]; %ONLY splice in the correct spot
    sequence = [sequence(moves(1,2):end) sequence(1:moves(1,2)-1)];
end