Created
January 14, 2010 22:13
-
-
Save paulgb/277567 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
# different functions that can be passed in | |
# (num_divisors is used by default) | |
uniq_factors = lambda x: len([p for p,n in factor(x)]) | |
count_factors = lambda x: sum(n for p,n in factor(x)) | |
num_divisors = lambda x: len(divisors(x)) | |
def plot_divisors(height=100, fun=num_divisors): | |
width = 2*height | |
m = matrix(height, width) | |
l = width / 2 | |
gen = iter(xrange(1, (height+1) ** 2)) | |
for t in range(0, height+1): | |
for j in range(l, l+t*2-1): | |
m[t-1, j] = fun(gen.next()) | |
l -= 1 | |
return matrix_plot(m) | |
plot_divisors() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment