Mercurial > hg > config
annotate python/prime.py @ 728:6ba565f99696
cache credentials for a session
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 05 Dec 2014 16:50:04 -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)) |