summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-10-14 03:33:06 +0000
committerrsiddharth <s@ricketyspace.net>2017-10-14 03:33:06 +0000
commit71b1de4198dad80ffc8755c34aa48a39ef512226 (patch)
tree83c5ca0be494812d90455913fed8b4cd23c2dafa /net/ricketyspace
parentc13f497cdf68d53ce087cc1e57db6b3047d46616 (diff)
(net ricketyspace sicp one thirtyone): Simplify pi functions.
* net/ricketyspace/sicp/one/thirtyone.scm (pi, pi-iter): Update functions.
Diffstat (limited to 'net/ricketyspace')
-rw-r--r--net/ricketyspace/sicp/one/thirtyone.scm16
1 files changed, 8 insertions, 8 deletions
diff --git a/net/ricketyspace/sicp/one/thirtyone.scm b/net/ricketyspace/sicp/one/thirtyone.scm
index f84f637..558361e 100644
--- a/net/ricketyspace/sicp/one/thirtyone.scm
+++ b/net/ricketyspace/sicp/one/thirtyone.scm
@@ -29,18 +29,18 @@
(product-iter term 1 next n)))
(define (pi precision)
- (let* ((n (lambda (x) (* (+ (quotient x 2) 1) 2))) ; numerator of term.
- (d (lambda (x) (+ (* (quotient (1+ x) 2) 2) 1))) ; denominator of term.
- (term (lambda (x) (/ (* (n x) 1.0) (* (d x) 1.0))))
+ (let* ((n (lambda (x) (if (even? x) (+ x 2) (+ x 1)))) ; numerator of term.
+ (d (lambda (x) (if (even? x) (+ x 1) (+ x 2)))) ; denominator of term.
+ (term (lambda (x) (/ (n x) (d x))))
(next (lambda (x) (1+ x))))
- (* (product term 1 next precision) 4)))
+ (* (product term 1.0 next precision) 4)))
(define (pi-iter precision)
- (let* ((n (lambda (x) (* (+ (quotient x 2) 1) 2))) ; numerator of term.
- (d (lambda (x) (+ (* (quotient (1+ x) 2) 2) 1))) ; denominator of term.
- (term (lambda (x) (/ (* (n x) 1.0) (* (d x) 1.0))))
+ (let* ((n (lambda (x) (if (even? x) (+ x 2) (+ x 1)))) ; numerator of term.
+ (d (lambda (x) (if (even? x) (+ x 1) (+ x 2)))) ; denominator of term.
+ (term (lambda (x) (/ (n x) (d x))))
(next (lambda (x) (1+ x))))
- (* (product-iter term 1 next precision) 4)))
+ (* (product-iter term 1.0 next precision) 4)))
;;; Guile REPL