#
# Solution to Project Euler problem 39
# Philippe Legault
#
# https://github.com/Bathlamos/Project-Euler-Solutions

from math import sqrt


# <1M possibilities, so compute directly
def compute():
	limit = 1000
	num_triples = [0] * (limit + 1)
	for i in range(1, limit / 2 + 1):
		for j in range(i, limit / 2 + 1):
			hypothenuse = i ** 2 + j ** 2
			perimeter = sqrt(hypothenuse) + i + j
			if perimeter <= limit and is_square(hypothenuse):
				num_triples[int(perimeter)] += 1
			if perimeter > limit:
				break
	return num_triples.index(max(num_triples))

def is_square(a):
  return int(sqrt(a)) ** 2 == a

if __name__ == "__main__":
	print(compute())
