From: Ramakrishnan Muthukrishnan Date: Sat, 9 Jul 2011 16:26:12 +0000 (+0530) Subject: solutions to 3.58 and 3.59 X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/nxhtml.html?a=commitdiff_plain;h=3451888d61bf357043ea479ff83901efb2828217;p=sicp.git solutions to 3.58 and 3.59 --- diff --git a/src/sicp/ex3_58.rkt b/src/sicp/ex3_58.rkt new file mode 100644 index 0000000..d0258fb --- /dev/null +++ b/src/sicp/ex3_58.rkt @@ -0,0 +1,13 @@ +#lang racket + +(define (expand num den radix) + (cons-stream + (quotient (* num radix) den) + (expand (remainder (* num radix) den) den radix))) + +#| + +The function gives the digits in the fractional part of the division as a +stream. + +|# \ No newline at end of file diff --git a/src/sicp/ex3_59.rkt b/src/sicp/ex3_59.rkt new file mode 100644 index 0000000..2f80ee8 --- /dev/null +++ b/src/sicp/ex3_59.rkt @@ -0,0 +1,21 @@ +#lang racket + +;; part a +(define (integrate-series stream) + (define (integrate-iter S I) + (stream-map (lambda (s i) + (* s (/ 1 i))) + S + I)) + (integrate-iter stream + (integers-starting-from 1))) + +;; part b +(define sine-series + (cons-stream 0 (integrate-series cosine-series))) + +(define cosine-series + (cons-stream 1 (scale-stream (integrate-series sine-series) -1))) + + +