Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Created November 16, 2010 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandotsmith/702130 to your computer and use it in GitHub Desktop.
Save ryandotsmith/702130 to your computer and use it in GitHub Desktop.
(ns sicp
(:use clojure.test))
(defn square [num] (* num num))
(defn sum-of-squares [x y] (+ (square x) (square y)))
; assume x != y != z
(defn sum-of-larger-squares [x y z]
(cond
(and (< x y) (< x z));x is the smallest
(sum-of-squares y z)
(and (< y x) (< y z));y is the smallest
(sum-of-squares x z)
(and (< z x) (< z y));z is the smallest
(sum-of-squares x y)))
(deftest test-small-x
(is (= 25 (sum-of-larger-squares 2 3 4))))
(deftest test-small-y
(is (= 25 (sum-of-larger-squares 3 2 4))))
(deftest test-small-z
(is (= 25 (sum-of-larger-squares 3 4 2))))
(run-all-tests #"sicp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment