Factorial primes: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 30:
=={{header|ALGOL 68}}==
Basic task. Assumes LONG INT is at least 64 bits.
<
# for some factorial f #
Line 65:
FI
OD
END</
{{out}}
<pre>
Line 81:
=={{header|F_Sharp|F#}}==
<
// Factorial primes. Nigel Galloway: August 15th., 2022
let fN g=if Open.Numeric.Primes.MillerRabin.IsProbablePrime &g then Some(g) else None
let fp()=let rec fG n g=seq{let n=n*g in yield (fN(n-1I),-1,g); yield (fN(n+1I),1,g); yield! fG n (g+1I)} in fG 1I 1I|>Seq.filter(fun(n,_,_)->Option.isSome n)
fp()|>Seq.iteri(fun i (n,g,l)->printfn $"""%2d{i+1}: %3d{int l}!%+d{g} -> %s{let n=string(Option.get n) in if n.Length<41 then n else n[0..19]+".."+n[n.Length-20..]+" ["+string(n.Length)+" digits]"}""")
</syntaxhighlight>
{{out}}
<pre>
Line 122:
</pre>
=={{header|J}}==
<
2 1 1
3 2 1
Line 132:
39916801 11 1
479001599 12 _1
87178291199 14 _1</
(i.28x here would have given us an eleventh prime, but the task asked for the first 10, and the stretch goal requires considerable patience.)
=={{header|Julia}}==
<
limitedprint(n) = (s = string(n); n = length(s); return n <= 40 ? s : s[1:20] * "..." * s[end-19:end] * " ($n digits)")
Line 150:
showfactorialprimes(1000)
</
<pre>
1! + 1 -> 2
Line 189:
=={{header|LOLCODE}}==
Basic task, based on the Algol 68 sample.
<
for some factorial f
TLDR
Line 257:
KTHXBYE
</syntaxhighlight>
{{out}}
<pre>
Line 273:
=={{header|Phix}}==
<!--<
<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 294:
<span style="color: #000000;">i</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</
{{out}}
<pre>
Line 332:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
sub abr ($_) { .chars < 41 ?? $_ !! .substr(0,20) ~ '..' ~ .substr(*-20) ~ " ({.chars} digits)" }
Line 342:
++$limit and printf "%2d: %3d! + 1 = %s\n", $limit, $_, abr f +1 if (f +1).is-prime;
exit if $limit >= 30
}</
{{out}}
<pre> 1: 1! + 1 = 2
Line 379:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./fmt" for Fmt
Line 395:
i = i + 1
f = f * i
}</
{{out}}
Line 415:
{{libheader|Wren-gmp}}
This takes about 28.5 seconds to reach the 33rd factorial prime on my machine (Core i7) with the last two being noticeably slower to emerge. Likely to be very slow after that as the next factorial prime is 1477! + 1.
<
import "./fmt" for Fmt
Line 436:
}
i = i + 1
}</
{{out}}
|