Ultra useful primes: Difference between revisions
m
syntax highlighting fixup automation
m (J) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 25:
Uses Algol 68G's LONG LONG INT which has programmer-specifiable precision. Uses Miller Rabin primality testing.
{{libheader|ALGOL 68-primes}}
<
PR precision 650 PR # set number of digits for LONG LOMG INT #
# 2^(2^10) has 308 digits but we need more for #
Line 42:
DO SKIP OD
OD
END</
{{out}}
<pre>
Line 50:
=={{header|Arturo}}==
<
k: 1
p: (2^2^n) - k
Line 63:
print repeat "-" 10
loop 1..10 'x ->
print [(pad to :string x 3) "|" (pad.right to :string ultraUseful x 4)]</
{{out}}
Line 82:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<
: useful ( -- list )
Line 88:
[ 2^ 2^ 1 lfrom [ - prime? ] with lfilter car ] lmap-lazy ;
10 useful ltake [ pprint bl ] leach nl</
{{out}}
<pre>
Line 96:
=={{header|Go}}==
{{libheader|GMP(Go wrapper)}}
<
import (
Line 123:
fmt.Printf("%2d %d\n", n, a(n))
}
}</
{{out}}
Line 148:
Implementation:
<
ref=. 2x^2^y+1
k=. 1
while. -. 1 p: ref-k do. k=. k+2 end.
}}"0</
I don't have the patience to get this little laptop to compute the first 10 such elements, so here I only show the first five:
<
1 3 5 15 5</
=={{header|Julia}}==
<
nearpow2pow2prime(n) = findfirst(k -> isprime(2^(big"2"^n) - k), 1:10000)
@time println([nearpow2pow2prime(n) for n in 1:12])
</
<pre>
[1, 3, 5, 15, 5, 59, 159, 189, 569, 105, 1557, 2549]
Line 172:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
FindUltraUsefulPrimeK[n_] := Module[{num, tmp},
num = 2^(2^n);
Line 186:
]
res = FindUltraUsefulPrimeK /@ Range[13];
TableForm[res, TableHeadings -> Automatic]</
{{out}}
<pre>1 1
Line 202:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use feature 'say';
Line 220:
}
say join ' ', useful 1..13;</
{{out}}
<pre>1 3 5 15 5 59 159 189 569 105 1557 2549 2439</pre>
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
Line 252:
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
Line 262:
The first 10 take less than a quarter second. 11 through 13, a little under 30 seconds. Drops off a cliff after that.
<syntaxhighlight lang="raku"
(|$n).map: {
my $p = 1 +< ( 1 +< $_ );
Line 271:
put useful 1..10;
put useful 11..13;</
{{out}}
<pre>1 3 5 15 5 59 159 189 569 105
Line 277:
=={{header|Sidef}}==
<
say("----------")
Line 283:
var t = 2**(2**n)
printf("%2d %d\n", n, {|k| t - k -> is_prob_prime }.first)
}</
{{out}}
<pre>
Line 309:
{{libheader|Wren-fmt}}
Manages to find the first ten but takes 84 seconds to do so.
<
import "./fmt" for Fmt
Line 327:
System.print(" n k")
System.print("----------")
for (n in 1..10) Fmt.print("$2d $d", n, a.call(n))</
{{out}}
Line 347:
{{libheader|Wren-gmp}}
The following takes about 17 seconds to get to n = 13 but 7 minutes 10 seconds to reach n = 14. I didn't bother after that.
<
import "./fmt" for Fmt
Line 365:
System.print(" n k")
System.print("----------")
for (n in 1..14) Fmt.print("$2d $d", n, a.call(n))</
{{out}}
|