Permalink
Browse files

chpt2 ex2.12

  • Loading branch information...
1 parent 042bf08 commit 8ce7030d038c75a2c88c77590d34427b2999cb80 Sidhant Godiwala committed Mar 20, 2012
Showing with 41 additions and 0 deletions.
  1. +41 −0 src/sicp/chpt2/ex2_12.clj
View
@@ -0,0 +1,41 @@
+(ns sicp.chpt2.ex2-12)
+
+
+(defrecord Interval [lb ub])
+
+
+(defn make-interval
+ [lb ub]
+ (Interval. lb ub))
+
+
+(defn lower-bound
+ [i]
+ (.lb i))
+
+
+(defn upper-bound
+ [i]
+ (.ub i))
+
+
+(defn make-center-percent
+ [c p]
+ (let [width (* (/ p 100) c)]
+ (make-interval (- c width)
+ (+ c width))))
+
+
+(defn center
+ [i]
+ (/ (+ (lower-bound i)
+ (upper-bound i))
+ 2))
+
+
+(defn percent
+ [i]
+ (let [c (center i)]
+ (* (/ (- (upper-bound i) c)
+ c)
+ 100)))

0 comments on commit 8ce7030

Please sign in to comment.