Sequence of primes by trial division: Difference between revisions
Content added Content deleted
Jazzedpineda (talk | contribs) (→Delphi: Add EasyLang) |
(→OCaml: add) |
||
Line 2,133: | Line 2,133: | ||
1993 1997 1999 |
1993 1997 1999 |
||
</pre> |
</pre> |
||
=={{header|OCaml}}== |
|||
<syntaxhighlight lang="ocaml">let is_prime n = |
|||
let rec test x = |
|||
x * x > n || n mod x <> 0 && 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 seq_prime = |
|||
Seq.ints 2 |> Seq.filter is_prime |
|||
let () = |
|||
seq_prime |> Seq.take 25 |> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97</pre> |
|||
=={{header|Oforth}}== |
=={{header|Oforth}}== |