Repunit primes: Difference between revisions

Add PARI/GP implementation
(Added Quackery.)
(Add PARI/GP implementation)
 
(5 intermediate revisions by 3 users not shown)
Line 304:
Base 35: [313 1297]
Base 36: [2]
</pre>
 
=={{header|J}}==
Slow (runs a few minutes):
<syntaxhighlight lang="j">repunitp=. 1 p: ^&x: %&<: [
 
(2 + i. 15) ([ ;"0 repunitp"0/ <@# ]) i.&.(p:inv) 1000</syntaxhighlight>
{{out}}
<pre>
┌──┬─────────────────────────────────────────┐
│2 │2 3 5 7 13 17 19 31 61 89 107 127 521 607│
├──┼─────────────────────────────────────────┤
│3 │3 7 13 71 103 541 │
├──┼─────────────────────────────────────────┤
│4 │2 │
├──┼─────────────────────────────────────────┤
│5 │3 7 11 13 47 127 149 181 619 929 │
├──┼─────────────────────────────────────────┤
│6 │2 3 7 29 71 127 271 509 │
├──┼─────────────────────────────────────────┤
│7 │5 13 131 149 │
├──┼─────────────────────────────────────────┤
│8 │3 │
├──┼─────────────────────────────────────────┤
│9 │ │
├──┼─────────────────────────────────────────┤
│10│2 19 23 317 │
├──┼─────────────────────────────────────────┤
│11│17 19 73 139 907 │
├──┼─────────────────────────────────────────┤
│12│2 3 5 19 97 109 317 353 701 │
├──┼─────────────────────────────────────────┤
│13│5 7 137 283 883 991 │
├──┼─────────────────────────────────────────┤
│14│3 7 19 31 41 │
├──┼─────────────────────────────────────────┤
│15│3 43 73 487 │
├──┼─────────────────────────────────────────┤
│16│2 │
└──┴─────────────────────────────────────────┘
</pre>
 
Line 471 ⟶ 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 689 ⟶ 752:
{{works with|HP|49}}
≪ 0 1 4 ROLL '''START''' OVER * 1 + '''NEXT''' NIP
≫ '<span style="color:blue">REPUB</span>' STO <span style="color:grey">@ ( n b → Rb(n) )</span>
≪ 16 2 '''FOR''' b
{ }
2 1000 '''FOR''' n
'''IF''' n b <span style="color:blue">REPUB</span> ISPRIME? '''THEN''' n + '''END'''
'''NEXT'''
-1 '''STEP'''
"Done."
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
Line 878 ⟶ 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