Last active
August 29, 2015 14:10
-
-
Save rigibun/c9ff5b00a41e06988cda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (product a next b) | |
(define (iproduct p a next) | |
(if (<= a b) | |
(iproduct (* a p) (next a) next) | |
p)) | |
(iproduct 1 a next)) | |
(define (isprime? x) | |
(define (iisprime? i) | |
(cond ((> i (sqrt x)) #t) | |
((= (modulo x i) 0) #f) | |
(else (iisprime? (+ i 1))))) | |
(iisprime? 2)) | |
(define (next-prime x) | |
(define (f i) | |
(if (isprime? i) | |
i | |
(f (+ i 1)))) | |
(f (+ x 1))) | |
(print (product 2 next-prime 1000)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment