diff options
author | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-05-26 14:41:16 +0200 |
---|---|---|
committer | gabrieldemarmiesse <gabriel.demarmiesse@teraki.com> | 2018-05-27 14:14:29 +0200 |
commit | f35173fba8614b83d26ce11c9a34af5fc3b3bc71 (patch) | |
tree | 7de1a76a7bcd7eed5aed8ccfc00c8bf39d2e6c4d /docs/examples/tutorial/cython_tutorial/primes.py | |
parent | 45df48301b0ab5dd35e9d68581b57f15b69dd74f (diff) | |
download | cython-f35173fba8614b83d26ce11c9a34af5fc3b3bc71.tar.gz |
Now all the files in the example directory are tested.
Diffstat (limited to 'docs/examples/tutorial/cython_tutorial/primes.py')
-rw-r--r-- | docs/examples/tutorial/cython_tutorial/primes.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/examples/tutorial/cython_tutorial/primes.py b/docs/examples/tutorial/cython_tutorial/primes.py new file mode 100644 index 000000000..5e0d32e69 --- /dev/null +++ b/docs/examples/tutorial/cython_tutorial/primes.py @@ -0,0 +1,19 @@ + +def primes(kmax): + result = [] + if kmax > 1000: + kmax = 1000 + + p = [0] * 1000 + k = 0 + n = 2 + while k < kmax: + i = 0 + while i < k and n % p[i] != 0: + i += 1 + if i == k: + p[k] = n + k += 1 + result.append(n) + n += 1 + return result |