All pastes #606133 Raw Edit

Euler problem 54

public python v1 · immutable
·published 2007-07-06 17:46 UTC
rendered paste body
from math import sqrtdef get_tri_idx(n):    return max(-0.5+0.5*sqrt(1+(8*n)), -0.5-0.5*sqrt(1+(8*n)))def get_pent_idx(n):    return max((0.5+sqrt(.25+6*n))/3, (0.5-sqrt(.25+6*n))/3)def hexag(n):    return n*((2*n)-1)for i in range(144,100000):    new_hex = hexag(i)    tri_idx = get_tri_idx(new_hex)    if tri_idx == int(tri_idx):        pent_idx = get_pent_idx(new_hex)        if pent_idx == int(pent_idx):            print "T_%s = P_%s = H_%s = %s" % (tri_idx, pent_idx, i, new_hex)            break