Skip to content

Instantly share code, notes, and snippets.

@robertpostill
Created November 6, 2010 04:45
Show Gist options
  • Save robertpostill/665205 to your computer and use it in GitHub Desktop.
Save robertpostill/665205 to your computer and use it in GitHub Desktop.
Third part of SICP exercise 1.3
(define (smallest-of-the-two x y)
(if (<= x y)
x
y))
(define (smallest-of-the-two? x y)
(if (= (smallest-of-the-two x y) x)
true
false))
(define (smaller-than-thou x y z)
(if (and
(smallest-of-the-two? x y)
(smallest-of-the-two? x z))
x
false))
(define (smallest-of-the-three a b c)
(or
(smaller-than-thou a b c)
(smaller-than-thou b a c)
(smaller-than-thou c a b)))
(define (add-the-two-largest a b c)
(define remainder (smallest-of-the-three a b c))
(define subtotal (+ a b c))
(- subtotal remainder))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment