Mercurial > hg > config
annotate python/prime.py @ 767:35f8751c0930
it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 28 Jan 2016 14:02:17 -0800 |
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)) |