(* A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^(2) + b^(2) = c^(2) For example, 3^(2) + 4^(2) = 9 + 16 = 25 = 5^(2). There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. *) (* is a pythagorean triplet *) let ptriplet a b c = ( a*a + b*b = c*c );; let rec search a b = if (a>332) then 0 else if (b>499) then search (a+1) (a+1) else let c=(1000-a-b) in if ((a*a)+(b*b)=(c*c)) then (a*b*c) else search a (b+1) ;; Printf.printf "%d\n" (search 0 0)