Last active
December 19, 2015 23:28
-
-
Save polymorphm/6034498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
# -*- mode: python; coding: utf-8 -*- | |
from __future__ import absolute_import, print_function | |
assert unicode is not str | |
assert str is bytes | |
import sys, datetime | |
def find_prime(prime_from): | |
assert isinstance(prime_from, int) | |
prime_from = max(2, prime_from) | |
if prime_from == 2: | |
return 2 | |
if not prime_from % 2: | |
prime_from += 1 | |
while True: | |
for d in xrange(3, prime_from, 2): | |
if not prime_from % d: | |
break | |
else: | |
return prime_from | |
prime_from += 2 | |
def main(): | |
if len(sys.argv) != 3: | |
print('usage: {} <prime_from> <prime_count>'.format(sys.argv[0]), file=sys.stderr) | |
exit(2) | |
prime_from = int(sys.argv[1]) | |
prime_count = int(sys.argv[2]) | |
begin_time = datetime.datetime.now() | |
print('{}: begin test (prime_from is {!r}; prime_count is {!r})'.format( | |
begin_time.ctime(), prime_from, prime_count)) | |
for prime_i in xrange(prime_count): | |
prime_from = find_prime(prime_from) | |
print('{}: found prime ({!r})'.format( | |
datetime.datetime.now().ctime(), prime_from)) | |
prime_from += 1 | |
end_time = datetime.datetime.now() | |
work_time = end_time - begin_time | |
print('{}: end of test (work time is {!r} days {!r} seconds {!r} microseconds)'.format( | |
end_time.ctime(), work_time.days, work_time.seconds, work_time.microseconds)) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- mode: python; coding: utf-8 -*- | |
assert str is not bytes | |
import sys, datetime | |
def find_prime(prime_from): | |
assert isinstance(prime_from, int) | |
prime_from = max(2, prime_from) | |
if prime_from == 2: | |
return 2 | |
if not prime_from % 2: | |
prime_from += 1 | |
while True: | |
for d in range(3, prime_from, 2): | |
if not prime_from % d: | |
break | |
else: | |
return prime_from | |
prime_from += 2 | |
def main(): | |
if len(sys.argv) != 3: | |
print('usage: {} <prime_from> <prime_count>'.format(sys.argv[0]), file=sys.stderr) | |
exit(2) | |
prime_from = int(sys.argv[1]) | |
prime_count = int(sys.argv[2]) | |
begin_time = datetime.datetime.now() | |
print('{}: begin test (prime_from is {!r}; prime_count is {!r})'.format( | |
begin_time.ctime(), prime_from, prime_count)) | |
for prime_i in range(prime_count): | |
prime_from = find_prime(prime_from) | |
print('{}: found prime ({!r})'.format( | |
datetime.datetime.now().ctime(), prime_from)) | |
prime_from += 1 | |
end_time = datetime.datetime.now() | |
work_time = end_time - begin_time | |
print('{}: end of test (work time is {!r} days {!r} seconds {!r} microseconds)'.format( | |
end_time.ctime(), work_time.days, work_time.seconds, work_time.microseconds)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment