Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:
- #Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...
- #Pentagonal Pn=n(3n-1)/2 1, 5, 12, 22, 35, ...
- #Hexagonal Hn=n(2n-1) 1, 6, 15, 28, 45, ...
- #It can be verified that T285 = P165 = H143 = 40755.
- #Find the next triangle number that is also pentagonal and hexagonal.
- #Every hexagonal number is a triangular number.
- #One can efficiently test whether a positive integer x is an hexagonal number by computing:
- #n=(sqrt(8x+1)+1)/4
- #If n is an integer, then x is the nth hexagonal number.
- #So. 40755 is the H143 number
- #Source: http://en.wikipedia.org/wiki/Hexagonal_number
- #One can efficiently test whether a positive integer x is an pentagonal number by computing:
- #n=(sqrt(24x+1)+1)/6
- #If n is an integer, then x is the nth pentagonal number.
- #So. 40755 is P165
- #Source: http://en.wikipedia.org/wiki/Pentagonal_number
- def isPentagonal(n):
- if (((24*n+1)**0.5)+1)%6 == 0:
- return True
- else:
- return False
- n = 144
- while True:
- hexagon = n*(2*n-1)
- if isPentagonal(hexagon):
- print hexagon
- break
- n += 1
Advertisement
Add Comment
Please, Sign In to add comment