Pythagorean triples: Difference between revisions
Content added Content deleted
(Added Kotlin) |
(→{{header|Haskell}}: Constrained the (primitive generation) test to terminate (at 10^7), + hlint, hindent) |
||
Line 1,706: | Line 1,706: | ||
Recursive primitive generation: |
Recursive primitive generation: |
||
<lang haskell>triangles :: Int -> [[Int]] |
<lang haskell>triangles :: Int -> [[Int]] |
||
triangles max_peri |
triangles max_peri |
||
| max_peri < 12 = [] |
|||
| otherwise = concat tiers |
|||
⚫ | |||
where |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
tmul t = |
|||
⚫ | |||
map |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
] |
|||
triangleCount max_p = (length t, sum $ map ((max_p `div`) . sum) t) |
|||
where |
|||
t = triangles max_p |
|||
main |
main :: IO () |
||
main = |
|||
⚫ | |||
mapM_ |
|||
⚫ | |||
[1 .. 7]</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre>10 (0,0) |
||
10 (0,0) |
|||
100 (7,17) |
100 (7,17) |
||
1000 (70,325) |
1000 (70,325) |
||
Line 1,728: | Line 1,736: | ||
100000 (7026,64741) |
100000 (7026,64741) |
||
1000000 (70229,808950) |
1000000 (70229,808950) |
||
10000000 (702309,9706567) |
10000000 (702309,9706567)</pre> |
||
... |
|||
</pre> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |