Mercurial > hg > config
annotate python/prime.py @ 760:d0b975ffabdf
http://serverfault.com/questions/132055/how-to-check-if-emacs-is-in-gui-mode-and-execute-tool-bar-mode-only-then
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 15 Dec 2015 12:32:34 -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)) |