Winner Paulo Uribe (turbf1)

2002-05-23 00:00:00 UTC

# NoCopyCatv7

by scchua

Status: Failed
Results: []

Code
```function xy = solver(kd,bx)

S1=size(kd,1);

s=0; count=0; s1=0;
for i=1:S1-1
for j=i+1:S1
if kd(i,j)~=-1
s=s+kd(i,j);
count=count+1;
end;
end;
end;

for i=1:S1-1
for j=i+1:S1
if s1==0
kd(i,j)=floor(10*(rand(1)));
else
kd(i,j)=floor((s1/count)*(rand(1)));
end;
end;
end;

c(1,1:2)=0+rand(1)/10;

if S1>1
c(2,1)=c(1,1)+kd(1,2);
c(2,2)=c(1,2);
end;

if S1>2
for a=3:S1
if (kd(1,a)+kd(2,a))>=kd(1,2)
for x=0.01:0.01:(bx(2)-bx(1))
if (sqrt(kd(1,a)^2-(x-c(1,1))^2)-sqrt(kd(2,a)^2-(x-c(2,1))^2)-(c(1,2)-c(2,2)))<0.001
c(a,1)=x;
break;
end;
end;
c(a,2)=sqrt(kd(1,a)^2-(c(a,1)-c(1,1))^2)+c(1,2);
else
a=a-1;
xi=[c(1:a,1)];
yi=[c(1:a,2)];
m=size(xi,1);
d=kd(1:a,a);
Y=(xi.^2+5*yi.^2-5*d.^2)/2;
k=0.5.*ones(m,1);
A=[xi yi k];
c1=inv(A'*A)*A'*Y;
c(a+1,1)=c1(1); c(a+1,2)=c1(2);
end;
end;
end;

xy=abs(c);

minx=bx(1)-min(xy(:,1));
miny=bx(3)-min(xy(:,2));
xy(:,1)=minx+xy(:,1);
xy(:,2)=miny+xy(:,2);

a=0.001;
while or(max(xy(:,1))>bx(2),max(xy(:,2))>bx(4))
cen(1)=(max(xy(:,1))-min(xy(:,1)))/2;
cen(2)=(max(xy(:,2))-min(xy(:,2)))/2;
xy(:,1)=cen(1)+(xy(:,1)*cos(a)-xy(:,2)*sin(a));
xy(:,2)=cen(2)+(xy(:,1)*sin(a)+xy(:,2)*cos(a));
minx=min(xy(:,1))-bx(1);
miny=min(xy(:,2))-bx(3);
xy(:,1)=xy(:,1)-minx;
xy(:,2)=xy(:,2)-miny;
a=a+0.001;
end;

figure, plot(xy(:,1),xy(:,2),'b*');```