~ubuntu-branches/ubuntu/trusty/pyrex/trusty-proposed

« back to all changes in this revision

Viewing changes to Demos/primes.pyx

  • Committer: Bazaar Package Importer
  • Author(s): Paul Brossier
  • Date: 2006-06-14 18:21:15 UTC
  • mto: (2.1.5 edgy) (4.1.1 lenny) (1.1.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060614182115-54t2s7w2azy5oyof
Tags: upstream-0.9.4.1
ImportĀ upstreamĀ versionĀ 0.9.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
def primes(int kmax):
2
 
        cdef int n, k, i
3
 
        cdef int p[1000]
4
 
        result = []
5
 
        if kmax > 1000:
6
 
                kmax = 1000
7
 
        k = 0
8
 
        n = 2
9
 
        while k < kmax:
10
 
                i = 0
11
 
                while i < k and n % p[i] <> 0:
12
 
                        i = i + 1
13
 
                if i == k:
14
 
                        p[k] = n
15
 
                        k = k + 1
16
 
                        result.append(n)
17
 
                n = n + 1
18
 
        return result
 
2
    cdef int n, k, i
 
3
    cdef int p[1000]
 
4
    result = []
 
5
    if kmax > 1000:
 
6
        kmax = 1000
 
7
    k = 0
 
8
    n = 2
 
9
    while k < kmax:
 
10
        i = 0
 
11
        while i < k and n % p[i] <> 0:
 
12
            i = i + 1
 
13
        if i == k:
 
14
            p[k] = n
 
15
            k = k + 1
 
16
            result.append(n)
 
17
        n = n + 1
 
18
    return result