Closest-pair problem: Difference between revisions

m (→‎{{header|Perl}}: revised comment regarding timings)
Line 2,458:
 
[1x2 double] [1x2 double] %The pair is [1.5 2] and [2 2] which is correct</lang>
 
=={{header|Microsoft Small Basic}}==
<lang smallbasic>' Closest Pair Problem
s="0.654682,0.925557,0.409382,0.619391,0.891663,0.888594,0.716629,0.996200,0.477721,0.946355,0.925092,0.818220,0.624291,0.142924,0.211332,0.221507,0.293786,0.691701,0.839186,0.728260,"
i=0
While s<>""
i=i+1
For j=1 To 2
k=Text.GetIndexOf(s,",")
ss=Text.GetSubText(s,1,k-1)
s=Text.GetSubTextToEnd(s,k+1)
pxy[i][j]=ss
EndFor
EndWhile
n=i
i=1
j=2
dd=Math.Power(pxy[i][1]-pxy[j][1],2)+Math.Power(pxy[i][2]-pxy[j][2],2)
ddmin=dd
ii=i
jj=j
For i=1 To n
For j=1 To n
dd=Math.Power(pxy[i][1]-pxy[j][1],2)+Math.Power(pxy[i][2]-pxy[j][2],2)
If dd>0 Then
If dd<ddmin Then
ddmin=dd
ii=i
jj=j
EndIf
EndIf
EndFor
EndFor
sqrt1=ddmin
sqrt2=ddmin/2
For i=1 To 20
If sqrt1=sqrt2 Then
Goto exitfor
EndIf
sqrt1=sqrt2
sqrt2=(sqrt1+(ddmin/sqrt1))/2
EndFor
exitfor:
TextWindow.WriteLine("the minimum distance "+sqrt2)
TextWindow.WriteLine("is between the points:")
TextWindow.WriteLine(" ["+pxy[ii][1]+","+pxy[ii][2]+"] and")
TextWindow.WriteLine(" ["+pxy[jj][1]+","+pxy[jj][2]+"]")</lang>
{{out}}
<pre>
the minimum distance 0,0779101913551750943201426138
is between the points:
[0.891663,0.888594] and
[0.925092,0.818220]
</pre>
 
=={{header|Objective-C}}==
1,392

edits