Factorial primes: Difference between revisions

(Upgraded to 'full' task.)
(→‎OCaml: add)
Line 28:
* [[Sequence_of_primorial_primes|Sequence of primorial primes]]
<br><br>
 
=={{header|ALGOL 68}}==
Basic task. Assumes LONG INT is at least 64 bits.
Line 197 ⟶ 198:
31: 546!-1 -> 14130200926141832545..99999999999999999999 [1260 digits]
</pre>
 
=={{header|J}}==
<syntaxhighlight lang="j"> (,. (-!)/"1)1>.(,. >.@(!inv)@<:) (#~ 1 p: ]) ~.,(!i.27x)+/1 _1
Line 213 ⟶ 215:
 
=={{header|Java}}==
 
[[User:Sjharper79|Sjharper79]] ([[User talk:Sjharper79|talk]])
 
Line 552 ⟶ 553:
9: 12! - 1 = 479001599
10: 14! - 1 = 87178291199
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let is_prime (_, n, _) =
let rec test x =
let d = n / x in x > d || x * d <> 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 factorials_plus_minus_one =
let rec next x y () =
Seq.Cons ((x, pred y, 0), Seq.cons (x, succ y, 1) (next (succ x) (succ x * y)))
in
next 1 1
 
let () =
let show (x, y, a) = Printf.printf "%3u! %c 1 = %u\n" x [|'-'; '+'|].(a) y in
factorials_plus_minus_one |> Seq.filter is_prime |> Seq.take 10 |> Seq.iter show</syntaxhighlight>
{{out}}
<pre>
1! + 1 = 2
2! + 1 = 3
3! - 1 = 5
3! + 1 = 7
4! - 1 = 23
6! - 1 = 719
7! - 1 = 5039
11! + 1 = 39916801
12! - 1 = 479001599
14! - 1 = 87178291199
</pre>
 
559

edits