Wilson primes of order n: Difference between revisions

Realize in F#
(Realize in F#)
Line 20:
 
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<lang fsharp>
// Wilson primes. Nigel Galloway: July 31st., 2021
let rec fN g=function n when n<2I->g |n->fN(n*g)(n-1I)
let fG (n:int)(p:int)=let g,p=bigint n,bigint p in (((fN 1I (g-1I))*(fN 1I (p-g))-(-1I)**n)%(p*p))=0I
[1..11]|>List.iter(fun n->printf "%2d -> " n; let fG=fG n in pCache|>Seq.skipWhile((>)n)|>Seq.takeWhile((>)11000)|>Seq.filter fG|>Seq.iter(printf "%d "); printfn "")
</lang>
{{out}}
<pre>
1 -> 5 13 563
2 -> 2 3 11 107 4931
3 -> 7
4 -> 10429
5 -> 5 7 47
6 -> 11
7 -> 17
8 ->
9 -> 541
10 -> 11 1109
11 -> 17 2713
</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
2,172

edits