diff options
author | rsiddharth <s@ricketyspace.net> | 2017-02-04 02:32:46 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2017-02-04 02:32:46 +0000 |
commit | b947a6167b51546a3deed1e99de33f10884e389e (patch) | |
tree | b29abf6bfaebc6fe800fbcb4ee2be52f8fd13339 | |
parent | 19ed602c1ba7dc2b933274f50085c9c4f0f1105c (diff) |
Add net/ricketyspace/sicp/one/sixteen.scm
-rw-r--r-- | net/ricketyspace/sicp/one/sixteen.scm | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/sixteen.scm b/net/ricketyspace/sicp/one/sixteen.scm new file mode 100644 index 0000000..8bbd735 --- /dev/null +++ b/net/ricketyspace/sicp/one/sixteen.scm @@ -0,0 +1,26 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +;;; _____________________________________ +;;; < successive squaring 𝚯(log n) drivel > +;;; ------------------------------------- +;;; \ +;;; \ +;;; ^__^ / +;;; (oo)\_______/ _________ +;;; (__)\ )=( ____|_ \_____ +;;; ||----w | \ \ \_____ | +;;; || || || || +;;; + +(define-module (net ricketyspace sicp one sixteen) + #:export (fast-expt-iter)) + +(define (sqr x) (expt x 2)) + +(define (fast-expt-iter b n a) + "Excercise 1.16." + (cond ((= n 0) a) + ((even? n) (fast-expt-iter b (- n 2) (* a (sqr b)))) + (else (fast-expt-iter b (- n 1) (* a b))))) |