Integer Right Triangles (Project Euler Problem 39)


Poblem

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?

Link to original problem description

Solution

   
 open System  
   
 let buildArrays xs ys zs limits = seq{  
                 for x in xs do   
                   for y in ys do   
                     if x < y then  
                       for z in zs do   
                         if (x*x + y*y = z*z) then  
                           for limit in limits do   
                             if (x + y + z = limit) then  
                               yield limit, x, y, z}  
   
 let First (a,b,c,d) = a  
   
 let pyhtosArrays = buildArrays [1..999] [1..999] [1..999] [1..999]   
               |> Seq.toList   
               |> List.map (fun x -> First x)  
   
 let results = pyhtosArrays |> Seq.countBy id   
               |> Seq.toList   
               |> List.sortByDescending snd  
   

Popular posts from this blog

Digit cancelling fractions (Project Euler Problem 33)

Consecutive Prime Sum (Project Euler - Problem 50)

Coin Sums (Project Euler Problem 31)