Skip to content

Instantly share code, notes, and snippets.

@emberian
Created August 4, 2012 04:04
Show Gist options
  • Save emberian/3254328 to your computer and use it in GitHub Desktop.
Save emberian/3254328 to your computer and use it in GitHub Desktop.
number = 1
#creates the nth triangle number
def triangle(number):
return (number * (number + 1)) / 2
#finds factors for triangle numbers
def factors(number):
num_factors = 0
for i in xrange(1, int(number**0.5) + 1):
if number % i == 0:
num_factors += 2
return num_factors
num_factors = 0
while num_factors < 500:
tri = triangle(number)
num_factors = factors(tri)
print tri
print num_factors
print number
number += 1
import pylab as plt
number = 1
#creates the nth triangle number
def triangle(number):
return (number * (number + 1)) / 2
#finds factors for triangle numbers
def factors(number):
num_factors = 0
for i in xrange(1, int(number**0.5) + 1):
if number % i == 0:
num_factors += 2
return num_factors
num_factors = 0
f = []
try:
while num_factors < 500:
tri = triangle(number)
f.append(factors(triangle(number)))
number += 1
except:
plt.plot(f)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment