"""
Triangle, pentagonal, and hexagonal numbers are generated by the
following formulae:
Triangle 	  	T(n)=n(n+1)/2       1, 3, 6, 10, 15, ...
Pentagonal      P(n)=n(3n-1)/2     1, 5, 12, 22, 35, ...
Hexagonal 	  	H(n)=n(2n-1)       1, 6, 15, 28, 45, ...

It can be verified that T_(285) = P_(165) = H_(143) = 40755.

Find the next triangle number that is also pentagonal and hexagonal.
"""

if __name__ == "__main__":
    import sys, os
    sys.path.append( os.path.join( os.getcwd(), '..' ) )

from euler_tools.progress_bar import ProgressBar

progress = ProgressBar(1000000)
max_iter = progress.max

for n_t in range(max_iter):
    progress.set_value(n_t)

    #Triangle
    result_t = n_t * (n_t + 1) / 2

    # Pentagonal
    success = False
    for n_p in range(max_iter):
        result_p = n_p * (3 * n_p - 1) / 2

        if result_p == result_t:
            success = True
            break

        if result_p > result_t:
            break

    if not success:
        continue

    n_h = -1
    #~ # Hexagonal
    #~ success = False
    #~ for n_h in range(max_iter):
        #~ result_h = n_h * (2 * n_h - 1)
        #~ if result_h == result_t:
            #~ success = True
            #~ break
#~
        #~ if result_h > result_t:
            #~ break
#~
    #~ if not success:
        #~ continue

    progress.clear()
    print "T: %s,\tP: %s,\tH: %s,\tResult:\t%s" % (n_t, n_p, n_h, result_t)


    #~ h =

progress.finished()
