Repunit primes: Difference between revisions

Add PARI/GP implementation
m (→‎J: minor optimization)
(Add PARI/GP implementation)
 
(One intermediate revision by one other user not shown)
Line 511:
16: 2
</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
default(parisizemax, "128M")
default(parisize, "64M");
 
 
repunitprimeinbase(n, base) = {
repunit = sum(i=0, n-1, base^i); /* Construct the repunit */
return(isprime(repunit)); /* Check if it's prime */
}
 
{
for(b=2, 40,
print("Base ", b, ": ");
for(n=1, 2700,
if(repunitprimeinbase(n, b), print1(n, " "))
);
print(""); /* Print a newline */
)
}
</syntaxhighlight>
 
=={{header|Perl}}==
Line 918 ⟶ 941:
 
Still takes a while - 11 minutes 20 seconds to get up to base 36 with a limit of 2700.
<syntaxhighlight lang="ecmascriptwren">/* repunit_primesRepunit_primes.wren */
 
import "./gmp" for Mpz
338

edits