annotate python/prime.py @ 258:2862f4453296

add a hack to override setuptools
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 02 Jan 2013 15:41:11 -0800
parents 8593b0384d3e
children b5a59c3e4421
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
238
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 #!/usr/bin/env python
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 def prime(number):
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 half = int(number / 2)
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 for i in range(2, half):
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 if not number % i:
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 return False
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8 return True
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9
253
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
10 def primes(n):
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
11 return [i for i in range(2,n)
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
12 if not [True for j in range(2,1 + i/2)
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
13 if not i%j]]
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
14
8593b0384d3e add a function for computing primes
Jeff Hammel <jhammel@mozilla.com>
parents: 238
diff changeset
15
238
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 if __name__ == '__main__':
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 import sys
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 for arg in sys.argv[1:]:
05728a85e19b add prime.py
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 print prime(int(arg))