projects
/
sicp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
4b55ba0
)
Added solution to 1.16.
author
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Fri, 9 Apr 2010 10:04:48 +0000
(15:34 +0530)
committer
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Fri, 9 Apr 2010 10:04:48 +0000
(15:34 +0530)
chapter1/ch1_2.clj
patch
|
blob
|
history
diff --git
a/chapter1/ch1_2.clj
b/chapter1/ch1_2.clj
index 89ccec5724b40e08704d0f3677d3beed4d5977c8..d6bb552e34c09ab6b3dff6fbfc4828e6748cdca2 100644
(file)
--- a/
chapter1/ch1_2.clj
+++ b/
chapter1/ch1_2.clj
@@
-478,3
+478,16
@@
TRACE t2494: => -0.39980345741334
(defn even? [x]
(= (rem x 2) 0))
+
+(defn square [x]
+ (* x x))
+
+;; exercise 1.16:
+(defn expt [b n]
+ (expt-iter b n 1))
+
+(defn expt-iter [b n a]
+ (cond (= n 0) a
+ (even? n) (expt-iter (square b) (/ n 2) a)
+ :else (expt-iter b (- n 1) (* a b))))
+