Quad-power prime seeds: Difference between revisions

lang -> syntaxhighlight
(Realize in F#)
(lang -> syntaxhighlight)
Line 29:
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>.
<langsyntaxhighlight 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 #
PR read "primes.incl.a68" PR # include prime utilities #
Line 95:
FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 118:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang=fsharp>
// 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
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"
[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}}
<pre>
Line 142:
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<langsyntaxhighlight lang=factor>USING: grouping io kernel lists lists.lazy math math.functions
math.primes prettyprint sequences tools.memory.private ;
 
Line 152:
 
"First fifty quad-power prime seeds:" print
50 quads ltake list>array 10 group simple-table.</langsyntaxhighlight>
{{out}}
<pre>
Line 164:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<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>
Line 200:
<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>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 224:
 
=={{header|Raku}}==
<langsyntaxhighlight 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 }
Line 236:
my $key = @qpps.first: * > $threshold, :k;
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@qpps[$key].&comma}";
}</langsyntaxhighlight>
{{out}}
<pre>First fifty quad-power prime seeds:
Line 261:
{{libheader|Wren-fmt}}
GMP allows us to stretch a little more.
<langsyntaxhighlight lang=ecmascript>import "./gmp" for Mpz
import "./fmt" for Fmt
 
Line 297:
}
n = n + 1
}</langsyntaxhighlight>
 
{{out}}
3,028

edits