Wilson primes of order n: Difference between revisions

m
→‎{{header|RPL}}: removed a debug instruction
(added RPL)
m (→‎{{header|RPL}}: removed a debug instruction)
 
(5 intermediate revisions by 4 users not shown)
Line 509:
11 | 17 2713
</pre>
 
=={{header|EasyLang}}==
{{trans|FreeBASIC}}
<syntaxhighlight>
func isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func is_wilson n p .
if p < n
return 0
.
prod = 1
p2 = p * p
for i = 1 to n - 1
prod = prod * i mod p2
.
for i = 1 to p - n
prod = prod * i mod p2
.
prod = (p2 + prod - pow -1 n) mod p2
if prod = 0
return 1
.
return 0
.
print "n: Wilson primes"
print "-----------------"
for n = 1 to 11
write n & " "
for p = 3 step 2 to 10099
if isprim p = 1 and is_wilson n p = 1
write p & " "
.
.
print ""
.
</syntaxhighlight>
 
 
=={{header|F_Sharp|F#}}==
Line 732 ⟶ 777:
<syntaxhighlight lang="j"> wilson=. 0 = (*:@] | _1&^@[ -~ -~ *&! <:@[)^:<:
(>: i. 11x) (;/@[ ,.;"0 wilson"0/ <@# ]) i.&.(p:inv) 11000
┌──┬───────────────┐
│1 │5 13 563 │
Line 982 ⟶ 1,027:
10: 11 1109
11: 17 2713</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
default("parisizemax", "1024M");
 
 
\\ Define the function wilsonprimes with a default limit of 11000
wilsonprimes(limit) = {
\\ Set the default limit if not specified
my(limit = if(limit, limit, 11000));
\\ Precompute factorial values up to the limit to save time
my(facts = vector(limit, i, i!));
\\ Sign variable for adjustment in the formula
my(sgn = 1);
print(" n: Wilson primes\n--------------------");
\\ Loop over the specified range (1 to 11 in the original code)
for(n = 1, 11,
print1(Str(" ", n, ": "));
sgn = -sgn; \\ Toggle the sign
\\ Loop over all primes up to the limit
forprime(p = 2, limit,
\\ Check the Wilson prime condition modified for PARI/GP
index=1;
if(n<2,index=1,index=n-1);
if(p > n && Mod(facts[index] * facts[p - n] - sgn, p^2) == 0,
print1(Str(p, " "));
)
);
print1("\n");
);
}
 
\\ Execute the function with the default limit
wilsonprimes();
</syntaxhighlight>
 
{{out}}
<pre>
n: Wilson primes
--------------------
1: 5 13 563
2: 3 11 107 4931
3: 7
4: 10429
5: 7 47
6: 11
7: 17
8:
9: 541
10: 11 1109
11: 17 2713
 
</pre>
 
=={{header|Perl}}==
Line 1,353 ⟶ 1,452:
 
=={{header|RPL}}==
{{works with|HPRPL|49HP-49C}}
« → maxp
« { }
Line 1,360 ⟶ 1,459:
'''IF''' DUP ISPRIME? NOT '''THEN''' NEXTPRIME '''END'''
'''WHILE''' DUP maxp < '''REPEAT'''
n 1 - FACT OVER n - FACT * -1 n ^ -
'''IF''' OVER SQ MOD NOT '''THEN''' SWAP OVER + LOOK SWAP '''END'''
NEXTPRIME
'''END'''
DROP 1 →LIST +
Line 1,524 ⟶ 1,623:
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./big" for BigInt
import "./fmt" for Fmt
 
var limit = 11000
1,150

edits