19 lines
536 B
Haskell
19 lines
536 B
Haskell
-- 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 Euler
|
|
|
|
solutions :: Int -> [(Int, Int, Int)]
|
|
solutions p = do
|
|
a <- [1 .. p `div` 2]
|
|
b <- [a .. p - 2 * a]
|
|
let c = p - (a + b)
|
|
guard $ a^2 + b^2 == c^2
|
|
return (a, b, c)
|
|
|
|
main = print $ maximumBy (compare `on` snd) $ map (id &&& length . solutions) [3..1000]
|