This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,15 @@
#lang racket
(define (dist z0 z1) (magnitude (- z1 z0)))
(define (dist* zs) (apply dist zs))
(define (closest-pair zs)
(if (< (length zs) 2)
-inf.0
(first
(sort (for/list ([z0 zs])
(list z0 (argmin (λ(z) (if (= z z0) +inf.0 (dist z z0))) zs)))
< #:key dist*))))
(define result (closest-pair '(0+1i 1+2i 3+4i)))
(displayln (~a "Closest points: " result))
(displayln (~a "Distance: " (dist* result)))

View file

@ -0,0 +1,2 @@
Closest points: (0+1i 1+2i)
Distance: 1.4142135623730951