(4.1 0.5)
.
magnituder
that takes a point and
returns its distance from the origin. Example:
> (magnituder '(4.5 3.1)) 5.4644304369257 > (magnituder '(-0.5 -0.5)) 0.7071067811865476
distance
that takes two points
and returns the distance between them. Example:
> (distance '(0 1) '(1 0)) 1.4142135623730951 > (distance '(3.4 -0.25) '(3.15 3.75)) 4.00780488547035
> (distance '(-1 1 0) '(1 0 1)) 2.449489742783178 > (distance '(-1 0 2.5 3) '(0 0.5 -1 0)) 4.743416490252569
Consider the definition of rem-smallest
given
below:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; (rem-smallest L) returns a list (s Lp) where s is the smallest
;;; element in L, and Lp is a list containing all the other elements in L.
;;; NOTE: L must be a nonempty list of numbers!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (rem-smallest L)
(if (equal? (cdr L) '())
(list (car L) '())
(let ((R (rem-smallest (cdr L))))
(if (> (car L) (car R))
(list (car R) (cons (car L) (car (cdr R))))
(list (car L) (cdr L))))))
Given a nonempty list of numbers L, this function returns
a list (s Lp) where s is the smallest element in L, and Lp
is a list containing all the other elements in L. For
example:
> (rem-smallest '(4 7 2 3 6)) (2 (4 7 3 6)) >Using
rem-smallest
, write a function
my-sort
that sorts a list of numbers into
ascending order. For example:
> (my-sort '(3 8 7 2 9 1 6 5 4)) (1 2 3 4 5 6 7 8 9) >
tric-to-tricf
that
converts a triangle from its coordinate to its
coordinate-free representation. Example:
> (tric-to-tricf '((0 0) (1 1) (1 0))) (1.4142135623730951 1 1) > (tric-to-tricf '((3.5 4.5) (3.5 4) (3 4))) (0.5 0.5 0.7071067811865476)
similar-cf?
that takes two
triangles in their coordinate-free representation and
returns true if the triangles are similar and false
otherwise. Recall: two triangles are similar if their
sides can be matched up so that for some constant
the constant times each side of the first yields the
length of the corresponding side of the second.
> (similar-cf? '(1 1 0.8) '(0.4 0.5 0.5)) #t > (similar-cf? '(1 1 1) '(2 2.2 2)) #f
similar-c?
that takes two
triangles in their coordinate representation and
returns true if the triangles are similar and false
otherwise.
Example:
> (similar-c? '((0 0) (1 1) (1 0)) '((2 2) (1.5 2) (1.5 1.5))) #t > (similar-c? '((3 4) (-1 5) (-1 -1)) '((0 10) (1 5) (-1 -10))) #f