From d022481e3c3e9337e22b9d92bf805065bd64d05f Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 1 Jul 2017 23:40:14 +0000 Subject: (net ricketyspace sicp one twentytwo): Add three-primes-gt. * net/ricketyspace/sicp/one/twentytwo.scm (three-primes-gt) (three-primes-gt-iter): New functions. --- net/ricketyspace/sicp/one/twentytwo.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'net') diff --git a/net/ricketyspace/sicp/one/twentytwo.scm b/net/ricketyspace/sicp/one/twentytwo.scm index 209afaf..7eab420 100644 --- 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))))) -- cgit v1.2.3