diff options
author | David Thompson <dthompson2@worcester.edu> | 2014-02-02 17:22:36 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2014-02-02 17:22:36 -0500 |
commit | 1a350525867996f57ebb5d7c428ba8929d4995c6 (patch) | |
tree | f5913ad377fa3569e1666064f3e72e2b9c08a81d | |
parent | d41e12af4b823cc348d4714e9aedede60853a639 (diff) |
Solve problem 7.
-rw-r--r-- | problem-7.scm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/problem-7.scm b/problem-7.scm new file mode 100644 index 0000000..edad5da --- /dev/null +++ b/problem-7.scm @@ -0,0 +1,21 @@ +(use-modules (srfi srfi-1)) + +(define (divisible? m n) + (zero? (modulo m n))) + +(define (divisible-by-any? x nums) + (any (lambda (n) + (divisible? x n)) + nums)) + +(define (nth-prime n) + (define (inner m count primes) + (cond ((= count n) + (car primes)) + ((divisible-by-any? m primes) + (inner (1+ m) count primes)) + (else + (inner (1+ m) (1+ count) (cons m primes))))) + (inner 2 0 '())) + +(nth-prime 10001) |