Mercurial > hg > config
comparison python/prime.py @ 253:8593b0384d3e
add a function for computing primes
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 Dec 2012 11:08:21 -0800 |
parents | 05728a85e19b |
children | b5a59c3e4421 |
comparison
equal
deleted
inserted
replaced
252:f8b65bb57678 | 253:8593b0384d3e |
---|---|
5 for i in range(2, half): | 5 for i in range(2, half): |
6 if not number % i: | 6 if not number % i: |
7 return False | 7 return False |
8 return True | 8 return True |
9 | 9 |
10 def primes(n): | |
11 return [i for i in range(2,n) | |
12 if not [True for j in range(2,1 + i/2) | |
13 if not i%j]] | |
14 | |
15 | |
10 if __name__ == '__main__': | 16 if __name__ == '__main__': |
11 import sys | 17 import sys |
12 for arg in sys.argv[1:]: | 18 for arg in sys.argv[1:]: |
13 print prime(int(arg)) | 19 print prime(int(arg)) |