Pythagorean triples: Difference between revisions
→{{header|Haskell}}: Reformatting an existing contribution for slightly more legibility
m (→using single evenness for determinacy: added and changed some comments, changed some REXX variable names.) |
(→{{header|Haskell}}: Reformatting an existing contribution for slightly more legibility) |
||
Line 1,678:
=={{header|Haskell}}==
<lang haskell>pytr
pytr n =
where prim a b _ = gcd a b == 1▼
filter
(\(_, a, b, c) -> a + b + c <= n)
[ (prim a b c, a, b, c)
| a <- [1 .. n]
, b <- [1 .. n]
, c <- [1 .. n]
, a < b && b < c
, a ^ 2 + b ^ 2 == c ^ 2 ]
where
main :: IO ()
main =
where xs = pytr 100▼
putStrLn $
"Up to 100 there are " ++
show (length xs) ++
" triples, of which " ++
show (length $ filter (\(x, _, _, _) -> x) xs) ++ " are primitive."
where
{{Out}}
<pre>Up to 100 there are 17 triples, of which 7 are primitive.</pre>
|