2012-11-07 16:00:00 UTC

# Spiral Center

Status: Passed
Results: 108428 (cyc: 7, node: 390)
CPU Time: 1.158
Score: 108439.0
Submitted at: 2012-11-01 08:06:28 UTC
Scored at: 2012-11-01 17:45:48 UTC

Current Rank: 1685th (Highest: 27th )
Basis for: Spiral and Center st (diff)

Code
```function xyout = solver(a, xyin, wts)
% Spiral with centroid adjust, expect small effect wrt knots
nr=size(xyin,1);
awork=a; % when placed zero out columns
xyout=xyin;
unmoved=ones(nr,1);
dxy=[1 1; -1 -1; -1 1;1 -1;1 0;0 1;-1 0;0 -1];

sc=0; % spiral count
xy_center=[0 0];

while any(awork(:))
sa=[(1:nr)' sum(awork,2)];
sa=sortrows(sa,-2);
node=sa(1);

xyout(node,:)=xy_center-[0 1]; % offset center to avoid knottiness
awork(node,:)=0;
awork(:,node)=0;

end

sc=sc+1;
xy_center=[round(5*sc*cosd(17*sc)) round(5*sc*sind(17*sc))]; %

end % while nodes to place

% Unmoved may have been over-mapped. Need to fix
% Also moves singles next to adjacency nodes to reduce knots
unmov_vec=find(unmoved);
for j=1:length(unmov_vec)
for idxy=1:8
if ~ismember(xyout(ptr,:)+dxy(idxy,:),xyout,'rows') % found an adjacent point
xyout(unmov_vec(j),:)=xyout(ptr,:)+dxy(idxy,:);
break
end
end % idxy
end % moving singles and unmoved next to adjacents

% Center Spiral to reduce wt effect, if any vs Knots
xy_offset=floor(mean(xyin));
xyout_offset=floor(mean(xyout));

xyout=xyout+repmat(xy_offset-xyout_offset,nr,1);

if size(unique(xyout,'rows'),1)<nr,xyout=xyin;end % safety net

end```