2012-11-07 16:00:00 UTC

# median position 2

by Ulf

Status: Passed
Results: 5500 (cyc: 4, node: 252)
CPU Time: 27.068
Score: 5506.31
Submitted at: 2012-11-02 09:37:19 UTC
Scored at: 2012-11-02 09:40:53 UTC

Current Rank: 1560th (Highest: 18th )
Based on: median position (diff)

Code
```function xyOut = solver(a, xyIn, wts)

%pos = xyIn+rand(size(xyIn));
pos = rand(size(xyIn));
N = size(xyIn,1);
ndim = 2;
gsize = 300;

%figure(2);
for i = 1:50
for node = randperm(N)
pos(node,:) = mean([pos(find(a(:,node)),:); pos(node,:)]);
end
if ~mod(i,10)
pos = pos-ones(N,1)*mean(pos);
pos = pos*(gsize/mean(sqrt(sum(pos.^2,2))));
end
%axis(gsize*2*[-1 1 -1 1]);
%     gplot(a,pos); drawnow
%     pause(.1);
end
xyOut = discretize(pos);

%gplot(a,xyOut,'-o'); drawnow

function xyOut = discretize(pos)
N = size(pos,1);
border = 10;
gsize = round(50*sqrt(N)+2*border);
%taken = sparse(gsize,gsize);
taken = false(gsize);
pos = pos - ones(N,1)*min(pos);
pos = pos ./(ones(N,1)*max(pos))*(gsize-1-2*border)+1+border;
for i = 1:N;
while taken(round(pos(i,1)),round(pos(i,2)))
pos(i,:) = pos(i,:) + rand(1,2)*2-1;
end
taken(round(pos(i,1)),round(pos(i,2))) = true;
end
xyOut = round(pos);
```