# -*- coding: utf-8 -*-
"""
Created on Fri Aug 26 09:38:59 2016

@author: efron
"""
'''
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.
'''


def triangular(n: int) -> int:
    return (n*(n+1)) // 2

def pentagonal(n: int) -> int:
    return (n*(3*n-1)) // 2
    
def hexagonal(n: int) -> int:
    return n*(2*n-1)


triangles = {triangular(n): n for n in range(1, 10**6)}
pentagons = {pentagonal(n): n for n in range(1, 10**6)}
hexagons = {hexagonal(n): n for n in range(1, 10**6)}

superGeometrics = [x for x in triangles if x in pentagons and x in hexagons]
print(superGeometrics)
for x in superGeometrics:
    print(x)
    print('triangle #: \t', triangles[x])
    print('pentagonal #: \t', pentagons[x])
    print('hexagonal #: \t', hexagons[x])
    print()