Skip to content

Instantly share code, notes, and snippets.

@bmabey
Forked from redsquirrel/gist:189192
Created September 19, 2009 21:07
Show Gist options
  • Save bmabey/189590 to your computer and use it in GitHub Desktop.
Save bmabey/189590 to your computer and use it in GitHub Desktop.
(defn square [x] (* x x))
(defn squared-sum [x y]
(+ (square x) (square y))
)
(defn squared-sum-of-two-greatest [x y z]
(if (> x y)
(if (> y z)
(squared-sum x y)
(squared-sum x z)
)
(if (> x z)
(squared-sum y x)
(squared-sum y z)
)
)
)
(squared-sum-of-two-greatest 2 1 3)
; # => 13
(squared-sum-of-two-greatest 5 5 9)
; # => 106
(squared-sum-of-two-greatest 1 3 4)
; # => 25
;; SICP 1.3
;; Exercise 1.3. Define a procedure that takes three numbers as
;; arguments and returns the sum of the squares of the two larger
;; numbers.
(define (square x) (* x x))
(define (squared-sum x y)
(+ (square x) (square y))
)
(define (squared-sum-of-two-greatest x y z)
(if (> x y)
(if (> y z)
(squared-sum x y)
(squared-sum x z)
)
(if (> x z)
(squared-sum y x)
(squared-sum y z)
)
)
)
(squared-sum-of-two-greatest 2 1 3)
; # => 13
(squared-sum-of-two-greatest 5 5 9)
; # => 106
(squared-sum-of-two-greatest 1 3 4)
; # => 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment