Skip to content

Instantly share code, notes, and snippets.

@aausch
Last active Dec 24, 2015
Embed
What would you like to do?
http://projecteuler.net/problem=9 A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
for b in range(1,500):
c = (- b ** 2 + 1000 * b - 500000)/(b-1000)
a = (c**2 - b**2)**0.5
if (a+b+c) == 1000 and int(a) == a and a > 0:
print a,b,c
print a * b * c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment