Skip to content

Instantly share code, notes, and snippets.

@dstnbrkr
Created March 4, 2011 21:38
Show Gist options
  • Save dstnbrkr/855741 to your computer and use it in GitHub Desktop.
Save dstnbrkr/855741 to your computer and use it in GitHub Desktop.
fermat test for primality
(define (is-fermat-prime? n iterations)
(or (<= iterations 0)
(if (= (modulo (expt (+ (random (- n 1)) 1) (- n 1)) n) 1)
(is-fermat-prime? n (- iterations 1))
#f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment