Created
October 7, 2014 13:45
-
-
Save levigross/907fcf590bc21226bf25 to your computer and use it in GitHub Desktop.
This program is slow, optimize it.
This file contains 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 python | |
number_range = range(1, 21) | |
def count(): | |
number = 21 | |
while True: | |
for n in number_range: | |
if number % n == 0: | |
if n == 20: | |
print number | |
return | |
else: | |
continue | |
else: | |
number+=1 | |
break | |
count() | |
# $ time python counter.py | |
# 232792560 | |
# real 1m3.392s | |
# user 1m3.294s | |
# sys 0m0.028s | |
# $ time pypy counter.py | |
# 232792560 | |
# real 0m8.720s | |
# user 0m8.694s | |
# sys 0m0.022s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment