@@ -0,0 +1,1512 @@
+'''%0A    Integer Right Triangles%0A    =======================%0A    If p is the perimeter of a right angle triangle with integral length sides,%0A    %7Ba,b,c%7D, there are exactly three solutions for p = 120.%0A%0A    %7B20,48,52%7D, %7B24,45,51%7D, %7B30,40,50%7D%0A%0A    For which value of p %E2%89%A4 1000, is the number of solutions maximised?%0A'''%0A%0A# In a right angle triangle a%5E2 + b%5E2 = c%5E2. Rather than search for right angle%0A# triangles of perimeter exactly p for each p, instead find all right angle%0A# triangles with p %3C= 1,000 in any order and tabulate them based on their%0A# perimeters.%0A#%0A# To avoid duplication by symmetry in a, b, we ensure a %3C= b in the search. In%0A# a right angle triangle the hypotenuse c is the largest side, so b %3C c also.%0A# And since a + b + c %3C= p_max and a %3C= b %3C c, it must be then a %3C p_max/3 and%0A# b %3C p_max/2 or the perimeter will be %3E than p_max.%0A%0Afrom math import sqrt%0A%0Ap_max = 1000%0Acounts = %5B0%5D * (p_max + 1)  # Extra element so can index as p instead of p - 1.%0A%0Afor a in range(1, int(p_max / 3)):%0A    for b in range(a, int(p_max / 2)):%0A        # Check c is an integer by rounding it to the closest integer and%0A        # confirming the equality without float operations.%0A        c = round(sqrt(a * a + b * b))%0A        if a * a + b * b == c * c:%0A            # Count the right triangle if perimeter is not larger than p_max.%0A            if a + b + c %3C= p_max:%0A                counts%5Ba + b + c%5D += 1%0A%0Amax_index, _ = max(enumerate(counts), key=lambda pair: pair%5B1%5D)%0A%0Aanswer = max_index  # = 840%0Aprint(answer)%0A

Add python implementation for problem 39.