commit 6e3f3adbfefdbaa4f5b180f59450d220c91856d4
parent 7f3fe782c04d93ad76b58fb0eae68ee17b4d5c79
Author: therealFIGBERT <figbertwelner@gmail.com>
Date: Wed, 29 Jan 2020 12:46:26 -0800
Add solution to problem 9
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/problem009.py b/problem009.py
@@ -0,0 +1,17 @@
+# problemName = "Special Pythagorean triplet"
+# problemNum = 9
+# solutionBy = "FIGBERT"
+# language = "Python"
+# dateCompleted = "28/01/2020"
+from math import sqrt
+
+def triplet(a, b):
+ c = sqrt(a**2 + b**2)
+ if a + b + c == 1000:
+ return int(a*b*c)
+ return False
+
+for (i, k) in [(a, b) for a in range(500) for b in range(500) if a < b]:
+ answer = triplet(i, k)
+ if answer:
+ print(f"The product of abc, where:\n\ta < b < c,\n\ta2 + b2 = c2,\n\ta + b + c = 1000\nis {answer}")