Created
June 11, 2015 15:34
-
-
Save juanmacuevas/807cdb87b16848bb9186 to your computer and use it in GitHub Desktop.
Calculate factors from the first X numbers
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/python | |
def factors(n): | |
return set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) | |
def print_factors(f): | |
for i in f: | |
print "%2s" % (i), | |
def calculate_factors(x): | |
for i in range(1,x+1): | |
f = sorted(list(factors(i)))[1:] | |
print_factors(f) | |
calculate_factors(100) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By looking at the numbers with more factors than the previous numbers i discovered a nice sequence called Highly composite numbers