Cython has moved to github.
cython-devel
view tests/run/r_primes.pyx @ 1622:4f0327bdebc9
test for temp allocation bug in call
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Sat Jan 17 01:25:34 2009 -0800 (3 years ago) |
| parents | 6309e21af543 |
| children | 82d312a9f1fc |
line source
1 __doc__ = u"""
2 >>> primes(20)
3 [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
4 """
6 def primes(int kmax):
7 cdef int n, k, i
8 cdef int p[1000]
9 result = []
10 if kmax > 1000:
11 kmax = 1000
12 k = 0
13 n = 2
14 while k < kmax:
15 i = 0
16 while i < k and n % p[i] <> 0:
17 i = i + 1
18 if i == k:
19 p[k] = n
20 k = k + 1
21 result.append(n)
22 n = n + 1
23 return result
