sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit d022481e3c3e9337e22b9d92bf805065bd64d05f
parent 20de4932b291ebd0a24e6fcf5152f972bd80d4e9
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat,  1 Jul 2017 23:40:14 +0000

(net ricketyspace sicp one twentytwo): Add three-primes-gt.

* net/ricketyspace/sicp/one/twentytwo.scm (three-primes-gt)
(three-primes-gt-iter): New functions.

Diffstat:
net/ricketyspace/sicp/one/twentytwo.scm | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/net/ricketyspace/sicp/one/twentytwo.scm b/net/ricketyspace/sicp/one/twentytwo.scm @@ -4,8 +4,10 @@ (define-module (net ricketyspace sicp one twentytwo) #:use-module (net ricketyspace sicp utils) + #:use-module (srfi srfi-1) #:export (timed-prime-test - search-for-primes)) + search-for-primes + three-primes-gt)) (define (square x) (expt x 2)) @@ -46,3 +48,12 @@ ((odd-and-prime start) (cons start (search-for-primes (1+ start) end))) (else (search-for-primes (1+ start) end)))) + +(define (three-primes-gt n) + (three-primes-gt-iter n 10 '())) + +(define (three-primes-gt-iter n e l) + (cond ((> (length l) 3) (take l 3)) + (else (three-primes-gt-iter n + (+ e 10) + (search-for-primes n e)))))