~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to tools/primes.scm

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(define (prime? n)
2
 
  (define (smallest-divisor n)
3
 
    (find-divisor n 2))
4
 
  (define (find-divisor n test)
5
 
    (cond ((> (square test) n) n)
6
 
          ((divides? test n)   test)
7
 
          (else (find-divisor n (+ test 1)))))
8
 
  (define (divides? a b)
9
 
    (= (remainder b a) 0))
10
 
  (define (square n)
11
 
    (* n n))
12
 
  (= n (smallest-divisor n)))
13
 
 
14
 
(define count 0)
15
 
 
16
 
 
17
 
 
18
 
(define (display-prime n)
19
 
  (display n)
20
 
  (display ", ")
21
 
  (cond ((> count 8) (display "\n") (let count 0))
22
 
        (else (define count (+ count 1)))))
23
 
 
24
 
 
25
 
(define (primes n limit)
26
 
  (if (prime? n)
27
 
      (display-prime n) )
28
 
  (if (< n limit)
29
 
      (primes (+ n 1) limit)) )
30
 
 
31
 
(primes 3 5000)