update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
15
Task/Closest-pair-problem/Racket/closest-pair-problem-1.rkt
Normal file
15
Task/Closest-pair-problem/Racket/closest-pair-problem-1.rkt
Normal 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)))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Closest points: (0+1i 1+2i)
|
||||
Distance: 1.4142135623730951
|
||||
Loading…
Add table
Add a link
Reference in a new issue