p009.py 595 Bytes
Newer Older
1 2
# 
# Solution to Project Euler problem 9
3
# Copyright (c) Project Nayuki. All rights reserved.
4
# 
5
# https://www.nayuki.io/page/project-euler-solutions
6 7 8 9
# https://github.com/nayuki/Project-Euler-solutions
# 


10
# Computers are fast, so we can implement a brute-force search to directly solve the problem.
11
def compute():
12 13 14 15 16 17
	PERIMETER = 1000
	for a in range(1, PERIMETER + 1):
		for b in range(a + 1, PERIMETER + 1):
			c = PERIMETER - a - b
			if a * a + b * b == c * c:
				# It is now implied that b < c, because we have a > 0
18
				return str(a * b * c)
19 20 21 22


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