Mercurial > hg > config
annotate python/prime.py @ 536:0e0222cd3cab
.bashttw
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 26 Sep 2013 11:28:32 -0700 |
parents | 8593b0384d3e |
children | b5a59c3e4421 |
rev | line source |
---|---|
238 | 1 #!/usr/bin/env python |
2 | |
3 def prime(number): | |
4 half = int(number / 2) | |
5 for i in range(2, half): | |
6 if not number % i: | |
7 return False | |
8 return True | |
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 | 16 if __name__ == '__main__': |
17 import sys | |
18 for arg in sys.argv[1:]: | |
19 print prime(int(arg)) |