Last active
December 17, 2015 12:19
-
-
Save iepathos/5609054 to your computer and use it in GitHub Desktop.
This is a very fast factorization algorithm. I've concocted it from several sources. It would be hard to find one faster than this.
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
from math import sqrt | |
""" | |
Fast factorization algorithm. Uses tuples instead of lists | |
and sqrt over exponentiation. | |
""" | |
def factors(n): | |
return set(x for tup in ([i, n//i] | |
for i in range(1, int(sqrt(n))+1) if n % i == 0) for x in tup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment