Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Closest-pair-problem/Icon/closest-pair-problem.icon
Normal file
25
Task/Closest-pair-problem/Icon/closest-pair-problem.icon
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
record point(x,y)
|
||||
|
||||
procedure main()
|
||||
minDist := 0
|
||||
minPair := &null
|
||||
every (points := [],p1 := readPoint()) do {
|
||||
if *points == 1 then minDist := dSquared(p1,points[1])
|
||||
every minDist >=:= dSquared(p1,p2 := !points) do minPair := [p1,p2]
|
||||
push(points, p1)
|
||||
}
|
||||
|
||||
if \minPair then {
|
||||
write("(",minPair[1].x,",",minPair[1].y,") -> ",
|
||||
"(",minPair[2].x,",",minPair[2].y,")")
|
||||
}
|
||||
else write("One or fewer points!")
|
||||
end
|
||||
|
||||
procedure readPoint() # Skips lines that don't have two numbers on them
|
||||
suspend !&input ? point(numeric(tab(upto(', '))), numeric((move(1),tab(0))))
|
||||
end
|
||||
|
||||
procedure dSquared(p1,p2) # Compute the square of the distance
|
||||
return (p2.x-p1.x)^2 + (p2.y-p1.y)^2 # (sufficient for closeness)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue