euler39

まだ、python慣れないな。最大だから、本当はリストで持つ意味ないし、もっと効率よく求められそうだけれど。

# If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
# {20,48,52}, {24,45,51}, {30,40,50}
# For which value of p ≤ 1000, is the number of solutions maximised?

def is_ok(a, b, c):
    return a < b < c and a*a + b*b == c*c

def find(p):
    N = p/3
    return [(a, b, p-a-b) for a in xrange(1, N) for b in xrange(a, p) if is_ok(a, b, p-a-b)]

print(sum((sorted(map(find,xrange(1,1000)), key=len, reverse=True))[0][0]))