diff options
author | Ben Burwell <bburwell1@gmail.com> | 2013-04-11 00:03:50 -0400 |
---|---|---|
committer | Ben Burwell <bburwell1@gmail.com> | 2013-04-11 00:03:50 -0400 |
commit | 5b05b64a2a658c0f7d4eb5b09fa342c7375a776e (patch) | |
tree | bad4537081da8b969084cff6880e36418f13a97d /HW01.rkt |
Init
Diffstat (limited to 'HW01.rkt')
-rw-r--r-- | HW01.rkt | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/HW01.rkt b/HW01.rkt new file mode 100644 index 0000000..4885c33 --- /dev/null +++ b/HW01.rkt @@ -0,0 +1,54 @@ +#lang scheme + +;; circlearea +;; +;; find the area of a circle with radius r +(define + (circlearea r) + (* 3.142 (expt r 2)) +) + +;; between? +;; +;; check whether a is between x and y +(define + (between? a x y) + (if + (or + (and (< y a) (> x a)) ;; y < a < x + (and (> y a) (< x a)) ;; x < a < y + ) + #t + #f + ) +) + +;; shorter +;; +;; returns the list with fewer elements +(define + (shorter a b) + (if + (< (length a) (length b)) + a + b + ) +) + +;; righttri? +;; +;; checks whether 3 integers can be the side lengths +;; of a right triangle. +(define + (righttri? a b c) + (cond + ;; a is largest (b^2 + c^2 = a^2) + [ (and (> a b) (> a c)) (= (+ (expt b 2) (expt c 2)) (expt a 2)) ] + + ;; b is largest (a^2 + c^2 = b^2) + [ (and (> b a) (> b c)) (= (+ (expt a 2) (expt c 2)) (expt b 2)) ] + + ;; c is largest (a^2 + b^2 = c^2) + [ (and (> c a) (> c b)) (= (+ (expt a 2) (expt b 2)) (expt c 2)) ] + ) +)
\ No newline at end of file |