From 0b13772d4420e283dd04cb482284577f719b56a4 Mon Sep 17 00:00:00 2001 From: Philippe Zwietering Date: Fri, 26 Feb 2021 00:52:25 +0100 Subject: [PATCH] Finished the pythagorean triangle circumferences --- 39/main.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 39/main.py diff --git a/39/main.py b/39/main.py new file mode 100644 index 0000000..bab544d --- /dev/null +++ b/39/main.py @@ -0,0 +1,29 @@ +''' +If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120. + +{20,48,52}, {24,45,51}, {30,40,50} + +For which value of p ≤ 1000, is the number of solutions maximised? +''' + +import math + +def main(): + print("Hello this is Patrick") + + ps = [0]*1000 + + for a in range(1, 1000): + for b in range(1, 1000-a): + c2 = a**2 + b**2 + r = math.sqrt(c2) + + if c2 == int(r + 0.5) ** 2: + r = int(r + 0.5) + if a + b + r <= 1000: + ps[a + b + r - 1] += 1 + + print(ps.index(max(ps)) + 1) + +if __name__ == "__main__": + main() \ No newline at end of file