Skip to content

Instantly share code, notes, and snippets.

@paulgb
Created January 14, 2010 22:13
Show Gist options
  • Save paulgb/277567 to your computer and use it in GitHub Desktop.
Save paulgb/277567 to your computer and use it in GitHub Desktop.
# 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