Skip to content

Instantly share code, notes, and snippets.

@rigibun
Last active August 29, 2015 14:10
Show Gist options
  • Save rigibun/c9ff5b00a41e06988cda to your computer and use it in GitHub Desktop.
Save rigibun/c9ff5b00a41e06988cda to your computer and use it in GitHub Desktop.
(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