2012-11-07 16:00:00 UTC

# Imps live on the next door

by Bob

Status: Passed
Results: 1474 (cyc: 8, node: 498)
CPU Time: 9.871
Score: 1490.43
Submitted at: 2012-11-02 22:17:13 UTC
Scored at: 2012-11-02 22:26:14 UTC

Current Rank: 1315th (Highest: 1st )
Based on: The late worm (diff)
Basis for: try11 (diff)
Basis for: Imp twk (diff)
Basis for: tweaking neighbour next door (diff)
...and 1 other.

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

N=size(xyIn,1);

N=size(a,1);
X=logical(speye(N));
D=inf(N);

D(X)=0;
for n=1:N,
X=(a*X)>0;
X=X&(D>n);
if ~any(X(:)),break;end
D(X)=n;
end
D=min(N,D);
mD=mean(D,1);
E=D-repmat(mD,[size(D,1),1])-repmat(mD',[1,size(D,2)])+mean(mD);
[x,nill]=svd(E);
xyOut0=x(:,1:2);

xyOut = xyOut0;
% xyOut=N*xyOut0+randn(size(xyOut0))/1e3;
for ncut=1:2
M=a; M(1:size(M,1)+1:end)=1;
M=bsxfun(@rdivide,M,sum(M,2));
Mbeta=(((0.9)*eye(N)+0.1*M)^10);
for n1=1:120
xyOut=Mbeta*xyOut;
mxyOut=mean(xyOut,1);
cxyOut=cov(xyOut,1);
[c1,d1,c2]=svd(cxyOut);
xyOut=(xyOut-mxyOut(ones(N,1),:))*c1*diag(1./sqrt(.1+diag(d1)))*c2'; %sqrtm(pinv(.1*eye(2)+cxyOut));
end
[i,j]=find(a>0.01);
dd=sum((xyOut(i,:)-xyOut(j,:)).^2,2);
k=find(dd>4*mean(dd));
if isempty(k), break; end
a(i(k)+N*(j(k)-1))=0.01;
end
xyOut0=xyOut;

xyOut0=sqrt(N)*detrend(xyOut0,'constant')*diag(1./max(eps,std(xyOut0,1,1)));
K=10;
k=1;
[sxyOut0,idxequal]=sortrows(round(K*xyOut0)/K);
idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
xyOut=round(xyOut0*k);
while size(unique(xyOut,'rows'),1)~=N
k=k*2;
xyOut=xyOut0*k;
xyOut(idxequal,:)=(xyOut0(idxequal,:)+randn(numel(idxequal),2)/K)*k;
xyOut=round(xyOut);
end
if N<30 % small map knot lines
xyOut=2*xyOut+(randi(3,size(xyOut))-2);
end
%xyOut=bsxfun(@plus,xyOut,round(median(xyIn,1)-median(xyOut,1)));
dxy = round(wts*(xyOut-xyIn)./sum(wts)); % Howe's
xyOut = bsxfun(@minus,xyOut,dxy);

end
```