(define (find-closest-number goal numbers) (if (= 1 (length numbers)) (car numbers) (if (< (abs (- goal (car numbers))) (abs (- goal (find-closest goal (cdr numbers))))) (car numbers) (find-closest goal (cdr numbers))))) (define (find-closest goal lst comparator) (if (= 1 (length lst)) (car lst) (if (< (comparator goal (car lst)) (comparator goal (find-closest goal (cdr lst) comparator))) (car lst) (find-closest goal (cdr lst) comparator)))) (define (find-closest-number2 goal numbers) (find-closest goal numbers (lambda (a b) (abs (- a b))))) (define (find-closest-below goal numbers) (find-closest goal numbers (lambda (a b) (if (>= a b) (- a b) 99999)))) (define (list-or-not-cruncher base nonlist proc combiner lst) (if (null? lst) base (if (not (pair? lst)) nonlist (combiner (proc (car lst)) (list-or-not-cruncher base nonlist proc combiner (cdr lst)))))) (define (list? p) (list-or-not-cruncher #t #f (lambda (x) x) (lambda (f r) r) p)) (define (pick-closest closeness goal num1 num2) (if (< (closeness goal num1) (closeness goal num2)) num1 num2)) (define (find-closest goal lst closeness) (if (= 1 (length lst)) (car lst) (pick-closest closeness goal (car lst) (find-closest goal (cdr lst) closeness))))