Primality by trial division: Difference between revisions
Content added Content deleted
Jazzedpineda (talk | contribs) (Add EasyLang) |
(→OCaml: simplified & faster) |
||
Line 2,899: | Line 2,899: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<syntaxhighlight lang="ocaml">let is_prime n = |
<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 land 2 <> 0 |
|||
else n land 1 <> 0 && n mod 3 <> 0 && test 5</syntaxhighlight> |
|||
else loop (k+2) |
|||
in loop 3</syntaxhighlight> |
|||
=={{header|Octave}}== |
=={{header|Octave}}== |