Skip to content

Instantly share code, notes, and snippets.

@levigross
Created October 7, 2014 13:45
Show Gist options
  • Save levigross/907fcf590bc21226bf25 to your computer and use it in GitHub Desktop.
Save levigross/907fcf590bc21226bf25 to your computer and use it in GitHub Desktop.
This program is slow, optimize it.
#!/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