Closest-pair problem: Difference between revisions
Content added Content deleted
(Added Easylang) |
(added RPL) |
||
Line 4,224: | Line 4,224: | ||
closest pair is : 3 and 6 at distance 0.0779101914 |
closest pair is : 3 and 6 at distance 0.0779101914 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
Brute-force approach, because it's unlikely that anyone would use a RPL calculator to process a large set of points. |
|||
« → points |
|||
« 0 0 0 |
|||
1 points SIZE 1 - '''FOR''' j |
|||
j 1 + points SIZE '''FOR''' k |
|||
points j GET points k GET - ABS |
|||
'''IF''' DUP2 < '''THEN''' 4 ROLLD 3 DROPN j k ROT '''ELSE''' DROP '''END''' |
|||
'''NEXT NEXT''' ROT ROT |
|||
points SWAP GET points ROT GET |
|||
'''IF''' DUP2 RE SWAP RE < '''THEN''' SWAP '''END''' <span style="color:grey">@ sort by ascending x</span> |
|||
2 →LIST |
|||
» » '<span style="color:blue">CLOSEPR</span>' STO |
|||
{ (0,0) (1,0) (1,2) (3,4) (5,5) (7,5) (3,5) } <span style="color:blue">CLOSEPR</span> |
|||
{{out}} |
|||
<pre> |
|||
2: 8.60232526704 |
|||
1: { (0,0) (7,5) } |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<syntaxhighlight lang="ruby">Point = Struct.new(:x, :y) |
<syntaxhighlight lang="ruby">Point = Struct.new(:x, :y) |
||
Line 4,286: | Line 4,307: | ||
recursive 0.187000 0.000000 0.187000 ( 0.190000) |
recursive 0.187000 0.000000 0.187000 ( 0.190000) |
||
</pre> |
</pre> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
Courtesy http://dkokenge.com/rbp |
Courtesy http://dkokenge.com/rbp |