Finish 2012-11-07 16:00:00 UTC

Metatarsal

by Pavan

Status: Passed
Results: 10567 (cyc: 2, node: 225)
CPU Time: 38.203
Score: 10575.5
Submitted at: 2012-11-01 17:13:29 UTC
Scored at: 2012-11-01 21:21:35 UTC

Current Rank: 1588th (Highest: 6th )
Based on: Tarsal (diff)

Comments
Please login or create a profile.
Code
function xyOut = solver(a, xyIn, wts)

s = 100;
zmax = 50;
tweakdir = [1 0; 0 -1];
orig_mean = mean(xyIn, 1);
len = length(xyIn);

xyIn = (xyIn - repmat(orig_mean, len, 1)).*s + repmat(orig_mean, len, 1);
for z = 1:zmax
   xyIn = round(cell2mat(cellfun(@(a_row) mean(xyIn(a_row==1, :), 1), num2cell(a, 1), 'uni', false)'));
   tweak_overlap
   xyIn = (xyIn - repmat(orig_mean, len, 1)).*1.05 + repmat(orig_mean, len, 1);
end

xyOut = xyIn;
%shift mean back
xyOut = round(xyOut + repmat(orig_mean - mean(xyOut, 1), length(xyIn), 1));
tweak_overlap;

    function tweak_overlap
        [u I J] = unique(xyIn, 'rows');
        n = size(xyIn, 1) - size(u, 1);
        while(n>0)
            xyIn(setdiff(1:length(xyIn), I), :) = xyIn(setdiff(1:length(xyIn), I), :) + ones(n, 2) * tweakdir;
            [u I J] = unique(xyIn, 'rows');
            n = size(xyIn, 1) - size(u, 1);
        end
    end

end