Ascending primes: Difference between revisions

(Add Dylan implementation)
(→‎OCaml: add)
Line 1,098:
234589 235679 235789 245789 345679 345689 1234789 1235789
1245689 1456789 12356789 23456789</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let is_prime n =
let rec test x =
let q = n / x in x > q || x * q <> n && n mod (x + 2) <> 0 && test (x + 6)
in if n < 5 then n lor 1 = 3 else n land 1 <> 0 && n mod 3 <> 0 && test 5
 
let ascending_ints =
let rec range10 m d = if d < 10 then m + d :: range10 m (succ d) else [] in
let up n = range10 (n * 10) (succ (n mod 10)) in
let rec next l = if l = [] then [] else l @ next (List.concat_map up l) in
next [0]
 
let () =
List.filter is_prime ascending_ints
|> List.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}
<pre> 2 3 5 7 13 17 19 23 29 37 47 59 67 79 89 127 137 139 149 157 167 179 239 257 269 347 349 359 367 379 389 457 467 479 569 1237 1249 1259 1279 1289 1367 1459 1489 1567 1579 1789 2347 2357 2389 2459 2467 2579 2689 2789 3457 3467 3469 4567 4679 4789 5689 12347 12379 12457 12479 12569 12589 12689 13457 13469 13567 13679 13789 15679 23459 23567 23689 23789 25679 34589 34679 123457 123479 124567 124679 125789 134789 145679 234589 235679 235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789</pre>
 
=={{header|Pascal}}==
559

edits