Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

I am writing a function which takes two parameter p1 and p2 and returns p1 if it is closer to (0 0) than p2. P1 and P2 are 2d points.

I am writing a function which takes two parameter p1 and p2 and returns p1 if it is closer to (0 0) than p2. P1 and P2 are 2d points.

Here is my attempt in Racket,

(define ptcomparator (lambda (p1 p2)

            (if(<(distance(p1 (0 0)) (distance(p2 (0 0)))))

                   #t

                   #f)))

(define distance(lambda(x y)

 (sqrt(-(*(+(car x)(car y)(car x)(car y))(cdr x)(cdr y))(cdr x)(cdr y)))))

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question