Pythagorean triples: Difference between revisions

Content added Content deleted
(→‎{{header|Haskell}}: Reformatting an existing contribution for slightly more legibility)
(→‎{{header|Haskell}}: (Pruning out some redundant search space in existing contribution))
Line 1,683: Line 1,683:
(\(_, a, b, c) -> a + b + c <= n)
(\(_, a, b, c) -> a + b + c <= n)
[ (prim a b c, a, b, c)
[ (prim a b c, a, b, c)
| a <- [1 .. n]
| a <- xs
, b <- [1 .. n]
, b <- drop a xs
, c <- [1 .. n]
, c <- drop b xs
, a < b && b < c
, a ^ 2 + b ^ 2 == c ^ 2 ]
, a ^ 2 + b ^ 2 == c ^ 2 ]
where
where
xs = [1 .. n]
prim a b _ = gcd a b == 1
prim a b _ = gcd a b == 1