2012-11-07 16:00:00 UTC

# firstAndLast66

by Th B

Status: Passed
Results: 1235 (cyc: 7, node: 882)
CPU Time: 31.376
Score: 1267.59
Submitted at: 2012-11-07 12:44:44 UTC
Scored at: 2012-11-07 13:03:44 UTC

Current Rank: 30th (Highest: 1st )
Based on: line equations (diff)
Basis for: try197 (diff)
Basis for: fifa1 (diff)
Basis for: I believe I can fly (diff)
...and 4 others.

Code
```function xyOut = solver(a, xyIn, wts)
diag(sum(a));
[V,~]=eig(ans-a,ans);
N = length(a);
sN=sqrt(N);
[p1i,p2i] = find( triu(a,1));
[pickr,pickc] = find(tril(true(length(p1i)),-1));

for ss=1:3
[xy{ss} xy{ss+3}] = solver_alfonsoz (a, ss+1, N,sN, V+rand(N)/25);
end
xy{7} = solver_hannes(xyIn, N, V(:,2:3),0);

parfor ss=1:7
end

[ZBest,best] = min(NN);

xyOut = bsxfun(@minus,xy{best},round(wts*(xy{best}-xyIn)./sum(wts)));

sprev = rng(0,'twister');

for ii=1:2
for jiggle=1:15
xyOutZ=xyOut+randi([-ii ii],N,2);
if ans<ZBest && size(unique(xyOutZ,'rows'),1)==N
xyOut=xyOutZ;
ZBest=ans;
end
end
end

rng(sprev);
end

function [xyOut xyOut1] = solver_alfonsoz(a, ss, N,sN, V)
randn('seed',ss);
xyOut=V(:,2:3);
for ncut=1:2
Mbeta=((1-ss/15)*eye(N)+(ss/15)*bsxfun(@rdivide,a+eye(N),sum(a,2)+1))^10;
for n1=1:117
xyOut=Mbeta*xyOut;
bsxfun(@minus,xyOut,sum(xyOut)/N);
[c1,D]=svd(ans');
xyOut=ans*c1*diag(sN./(.1+D([1 4])))*c1';
end
[i,j]=find(a>0.002+ss*5.1e-4);
sum((xyOut(i,:)-xyOut(j,:)).^2,2);
k=find(ans>(3.15 + ss*0.102)*mean(ans));
if isempty(k), break; end
a(i(k)+N*(j(k)-1))=0.002+ss*5.1e-4;
end

xyOutH=xyOut;
single_idx = find(sum(a)==1);

for zsingle=1:2
sN*detrend(xyOut,'constant')*diag(1./std(xyOut,1,1));
k=5;
[sxyOut0,idxequal]=sortrows(round(15*ans));
idxequal=idxequal(all(~diff(sxyOut0,1,1),2));
xyOut=round(ans);
while size(unique(xyOut,'rows'),1)~=N
k=k*(1.0+ss*0.055);
xyOut=ans*k;
xyOut(idxequal,:)=(ans(idxequal,:)+randn(numel(idxequal),2)/(9+ss))*k;
xyOut=round(xyOut);
end
if zsingle==1
xyOut1=xyOut;
xyOut=xyOutH;
end
end
end

function xyOut = solver_hannes(xyIn, N, V,xyOut)
mult    = norm(max(xyIn)-min(xyIn))/norm(max(V)-min(V));
while size(unique(xyOut,'rows'),1)<N
xyOut       = round(V*mult);
[~,i]       = unique(xyOut,'rows');
m           = setdiff(1:N,i);
xyOut(m,:)  = xyOut(m,:) + randi([-1 1],length(m),2);
mult        = mult*1.5;
end
end

p1 = XYnew(p1i,:);
p2 = XYnew(p2i,:);
P = [p1 p2 p1-p2 p1(:,1).*p2(:,2)-p2(:,1).*p1(:,2)];
a = P(pickr,:);
b = P(pickc,:);
A = (a(:,1).*b(:,6) - a(:,2).*b(:,5) + b(:,7)) ...
.*(a(:,3).*b(:,6) - a(:,4).*b(:,5) + b(:,7));
B = (b(:,1).*a(:,6) - b(:,2).*a(:,5) + a(:,7)) ...
.*(b(:,3).*a(:,6) - b(:,4).*a(:,5) + a(:,7));

sum((A <=0)  & (B <=0));
end```