Created
August 4, 2012 04:04
-
-
Save emberian/3254328 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
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 |
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
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