Created
November 16, 2010 17:32
-
-
Save ryandotsmith/702130 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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