Riordan numbers: Difference between revisions
Content added Content deleted
(Riordan numbers in various BASIC dialents (QBasic, True BASIC and Yabasic)) |
(→{{Haskell}}: Added a Haskell version) |
||
Line 416: | Line 416: | ||
834086421 2358641376 6684761125 18985057351 |
834086421 2358641376 6684761125 18985057351 |
||
54022715451 154000562758 439742222071 1257643249140</pre> |
54022715451 154000562758 439742222071 1257643249140</pre> |
||
=={{header|Haskell}}== |
|||
<syntaxhighlight lang="haskell">--------------------- RIORDAN NUMBERS -------------------- |
|||
riordans :: [Integer] |
|||
riordans = |
|||
1 : |
|||
0 : |
|||
zipWith |
|||
div |
|||
( zipWith |
|||
(*) |
|||
[1 ..] |
|||
( zipWith |
|||
(+) |
|||
((2 *) <$> tail riordans) |
|||
((3 *) <$> riordans) |
|||
) |
|||
) |
|||
[3 ..] |
|||
-------------------------- TESTS ------------------------- |
|||
main :: IO () |
|||
main = do |
|||
putStrLn "First 32 Riordan terms:" |
|||
mapM_ print $ take 32 riordans |
|||
mapM_ |
|||
( \x -> |
|||
putStrLn |
|||
( ("\nDigit count of " <> show x <> "th Riordan term:\n") |
|||
<> (show . length . show) (riordans !! pred x) |
|||
) |
|||
) |
|||
[1000, 10000]</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>First 32 Riordan terms: |
|||
1 |
|||
0 |
|||
1 |
|||
1 |
|||
3 |
|||
6 |
|||
15 |
|||
36 |
|||
91 |
|||
232 |
|||
603 |
|||
1585 |
|||
4213 |
|||
11298 |
|||
30537 |
|||
83097 |
|||
227475 |
|||
625992 |
|||
1730787 |
|||
4805595 |
|||
13393689 |
|||
37458330 |
|||
105089229 |
|||
295673994 |
|||
834086421 |
|||
2358641376 |
|||
6684761125 |
|||
18985057351 |
|||
54022715451 |
|||
154000562758 |
|||
439742222071 |
|||
1257643249140 |
|||
Digit count of 1000th Riordan term: |
|||
472 |
|||
Digit count of 10000th Riordan term: |
|||
4765</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |
||
Line 424: | Line 500: | ||
#":(1e4-1){riordanext^:(1e4) x:1 0 |
#":(1e4-1){riordanext^:(1e4) x:1 0 |
||
4765</syntaxhighlight> |
4765</syntaxhighlight> |
||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
<syntaxhighlight lang="pli">showRiordan: procedure options( main ); /* find some Riordan numbers */ |
<syntaxhighlight lang="pli">showRiordan: procedure options( main ); /* find some Riordan numbers */ |