p009.py 595 Bytes
 Nayuki Minase committed Jul 19, 2015 1 2 ``````# # Solution to Project Euler problem 9 `````` Nayuki committed Dec 27, 2016 3 ``````# Copyright (c) Project Nayuki. All rights reserved. `````` Nayuki Minase committed Jul 19, 2015 4 ``````# `````` Nayuki Minase committed Feb 05, 2016 5 ``````# https://www.nayuki.io/page/project-euler-solutions `````` Nayuki Minase committed Jul 19, 2015 6 7 8 9 ``````# https://github.com/nayuki/Project-Euler-solutions # `````` Nayuki Minase committed Mar 12, 2016 10 ``````# Computers are fast, so we can implement a brute-force search to directly solve the problem. `````` Nayuki Minase committed Jul 22, 2015 11 ``````def compute(): `````` Nayuki Minase committed Mar 12, 2016 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 `````` Nayuki Minase committed Jul 23, 2015 18 `````` return str(a * b * c) `````` Nayuki Minase committed Jul 22, 2015 19 20 21 22 `````` if __name__ == "__main__": print(compute())``````