Klarner-Rado sequence: Difference between revisions

→‎{{header Haskell}}: Added a Haskell draft
(Added two AppleScript solutions.)
(→‎{{header Haskell}}: Added a Haskell draft)
Line 345:
{{out}}
<pre>Same as Phix entry.</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang=haskell>import Data.List (intercalate)
import Data.List.Ordered (union)
import Data.List.Split (chunksOf)
import Text.Printf
 
----------------------- KLARNER-RADO ---------------------
 
klarnerRado :: (Num a, Ord a, Enum a) => [a]
klarnerRado =
1 :
union
(succ . (* 2) <$> klarnerRado)
(succ . (* 3) <$> klarnerRado)
 
 
--------------------------- TEST -------------------------
main :: IO ()
main = do
putStrLn "First one hundred elements of the sequence:\n"
mapM_
putStrLn
( intercalate " "
<$> chunksOf
10
(printf "%3d" <$> take 100 klarnerRado)
)
 
putStrLn "\nKth and 10Kth elements of the sequence:\n"
mapM_
( putStrLn
. (<*>)
(flip (printf "%5dth %s %7d") " ->")
(klarnerRado !!)
)
[1000, 10000]</syntaxhighlight>
{{Out}}
<pre>First one hundred elements of the sequence:
 
1 3 4 7 9 10 13 15 19 21
22 27 28 31 39 40 43 45 46 55
57 58 63 64 67 79 81 82 85 87
91 93 94 111 115 117 118 121 127 129
130 135 136 139 159 163 165 166 171 172
175 183 187 189 190 193 202 223 231 235
237 238 243 244 247 255 256 259 261 262
271 273 274 279 280 283 319 327 331 333
334 343 345 346 351 352 355 364 367 375
379 381 382 387 388 391 405 406 409 418
 
Kth and 10Kth elements of the sequence:
 
1000th -> 8488
10000th -> 157654</pre>
 
=={{header|J}}==
Line 366 ⟶ 421:
(1e6-1){kr7e7
54381285</lang>
 
 
=={{header|Julia}}==
9,655

edits