Quad-power prime seeds: Difference between revisions
Content added Content deleted
(Realize in F#) |
(lang -> syntaxhighlight) |
||
Line 29: | Line 29: | ||
NB: The source of the ALGOL 68-primes library is on a Rosetta Code code page linked from the above.<br> |
NB: The source of the ALGOL 68-primes library is on a Rosetta Code code page linked from the above.<br> |
||
Note that to run this with ALGOL 68G under Windows (and probably Linux) a large heap size must be specified on the command line, e.g. <code>-heap 1024M</code>. |
Note that to run this with ALGOL 68G under Windows (and probably Linux) a large heap size must be specified on the command line, e.g. <code>-heap 1024M</code>. |
||
< |
<syntaxhighlight lang=algol68>BEGIN # find some Quad power prime seeds, numbers n such that: # |
||
# n^p + n + 1 is prime for p = 1, 2, 3, 4 # |
# n^p + n + 1 is prime for p = 1, 2, 3, 4 # |
||
PR read "primes.incl.a68" PR # include prime utilities # |
PR read "primes.incl.a68" PR # include prime utilities # |
||
Line 95: | Line 95: | ||
FI |
FI |
||
OD |
OD |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 118: | Line 118: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang=fsharp> |
||
// Quad-power prime seeds. Nigel Galloway: August 22nd., 2022 |
// Quad-power prime seeds. Nigel Galloway: August 22nd., 2022 |
||
let fG n g=let n=bigint(n:int) in let n=n**g+n+1I in Open.Numeric.Primes.MillerRabin.IsProbablePrime &n |
let fG n g=let n=bigint(n:int) in let n=n**g+n+1I in Open.Numeric.Primes.MillerRabin.IsProbablePrime &n |
||
Line 124: | Line 124: | ||
Seq.initInfinite((+)1)|>Seq.filter(fun n->let g=fG n in g 1&&g 2&&g 3&&g 4)|>Seq.take 50|>Seq.iter(printf "%d "); printfn "\n" |
Seq.initInfinite((+)1)|>Seq.filter(fun n->let g=fG n in g 1&&g 2&&g 3&&g 4)|>Seq.take 50|>Seq.iter(printf "%d "); printfn "\n" |
||
[1000000..1000000..10000000]|>Seq.scan(fun(n,g,x) l->let i,e=fN(g,l) in (n+i,e,l))(0,0,0)|>Seq.skip 1|>Seq.iter(fun(n,g,l)->printfn $"First element over %8d{l} is %9d{g} at index %3d{n}") |
[1000000..1000000..10000000]|>Seq.scan(fun(n,g,x) l->let i,e=fN(g,l) in (n+i,e,l))(0,0,0)|>Seq.skip 1|>Seq.iter(fun(n,g,l)->printfn $"First element over %8d{l} is %9d{g} at index %3d{n}") |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 142: | Line 142: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2022-04-03}} |
{{works with|Factor|0.99 2022-04-03}} |
||
< |
<syntaxhighlight lang=factor>USING: grouping io kernel lists lists.lazy math math.functions |
||
math.primes prettyprint sequences tools.memory.private ; |
math.primes prettyprint sequences tools.memory.private ; |
||
Line 152: | Line 152: | ||
"First fifty quad-power prime seeds:" print |
"First fifty quad-power prime seeds:" print |
||
50 quads ltake list>array 10 group simple-table.</ |
50 quads ltake list>array 10 group simple-table.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 164: | Line 164: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang=Phix>(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
Line 200: | Line 200: | ||
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 224: | Line 224: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
< |
<syntaxhighlight lang=perl6>use Lingua::EN::Numbers; |
||
my @qpps = lazy (1..*).hyper(:5000batch).grep: -> \n { my \k = n + 1; (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime } |
my @qpps = lazy (1..*).hyper(:5000batch).grep: -> \n { my \k = n + 1; (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime } |
||
Line 236: | Line 236: | ||
my $key = @qpps.first: * > $threshold, :k; |
my $key = @qpps.first: * > $threshold, :k; |
||
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@qpps[$key].&comma}"; |
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@qpps[$key].&comma}"; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First fifty quad-power prime seeds: |
<pre>First fifty quad-power prime seeds: |
||
Line 261: | Line 261: | ||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
GMP allows us to stretch a little more. |
GMP allows us to stretch a little more. |
||
< |
<syntaxhighlight lang=ecmascript>import "./gmp" for Mpz |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
Line 297: | Line 297: | ||
} |
} |
||
n = n + 1 |
n = n + 1 |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |