Wilson primes of order n: Difference between revisions

Add Factor
(Added Sidef)
(Add Factor)
Line 19:
:* [[Primality by Wilson's theorem]]
 
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<lang factor>USING: formatting infix io kernel literals math math.functions
math.primes math.ranges prettyprint sequences sequences.extras ;
 
<< CONSTANT: limit 11,000 >>
 
CONSTANT: primes $[ limit primes-upto ]
 
CONSTANT: factorials
$[ limit [1,b] 1 [ * ] accumulate* 1 prefix ]
 
: factorial ( n -- n! ) factorials nth ; inline
 
INFIX:: fn ( p n -- m )
factorial(n-1) * factorial(p-n) - -1**n ;
 
: wilson? ( p n -- ? ) [ fn ] keepd sq divisor? ; inline
 
: order ( n -- seq )
primes swap [ [ < ] curry drop-while ] keep
[ wilson? ] curry filter ;
 
: order. ( n -- )
dup "%2d: " printf order [ pprint bl ] each nl ;
 
" n: Wilson primes\n--------------------" print
11 [1,b] [ order. ] each</lang>
{{out}}
<pre>
n: Wilson primes
--------------------
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|Go}}==
1,808

edits