Super-Poulet numbers: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: odd-ol#nly optimisation, slightly nicer output.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19: | Line 19: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2022-04-03}} |
{{works with|Factor|0.99 2022-04-03}} |
||
< |
<syntaxhighlight lang="factor">USING: combinators.short-circuit io kernel lists lists.lazy math |
||
math.functions math.primes math.primes.factors prettyprint |
math.functions math.primes math.primes.factors prettyprint |
||
sequences ; |
sequences ; |
||
Line 33: | Line 33: | ||
1 lfrom [ super-poulet? ] lfilter ; |
1 lfrom [ super-poulet? ] lfilter ; |
||
20 super-poulets ltake [ pprint bl ] leach nl</ |
20 super-poulets ltake [ pprint bl ] leach nl</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 40: | Line 40: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Implementation (only good for the first 60 super-poulet numbers):< |
Implementation (only good for the first 60 super-poulet numbers):<syntaxhighlight lang="j">spou1=: {{ 2 = 2x(y&|)@^ y }} |
||
is_super_poulet=: {{ |
is_super_poulet=: {{ |
||
Line 50: | Line 50: | ||
end. |
end. |
||
0 |
0 |
||
}}"0</ |
}}"0</syntaxhighlight> |
||
Task example:< |
Task example:<syntaxhighlight lang="j"> 20{. (#~ is_super_poulet) 1+i.1e5 |
||
341 1387 2047 2701 3277 4033 4369 4681 5461 7957 8321 10261 13747 14491 15709 18721 19951 23377 31417 31609</ |
341 1387 2047 2701 3277 4033 4369 4681 5461 7957 8321 10261 13747 14491 15709 18721 19951 23377 31417 31609</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="ruby">using Primes |
||
divisors(n) = @view sort!(vec(map(prod, Iterators.product((p.^(0:m) for (p, m) in eachfactor(n))...))))[begin:end-1] |
divisors(n) = @view sort!(vec(map(prod, Iterators.product((p.^(0:m) for (p, m) in eachfactor(n))...))))[begin:end-1] |
||
Line 71: | Line 71: | ||
println("The first super-Poulet number over 1 million is the ", idx1m, "th one, which is ", spoulets[idx1m]) |
println("The first super-Poulet number over 1 million is the ", idx1m, "th one, which is ", spoulets[idx1m]) |
||
println("The first super-Poulet number over 10 million is the ", idx10m, "th one, which is ", spoulets[idx10m]) |
println("The first super-Poulet number over 10 million is the ", idx10m, "th one, which is ", spoulets[idx10m]) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
The first 20 super-Poulet numbers are: [341, 1387, 2047, 2701, 3277, 4033, 4369, 4681, 5461, 7957, 8321, 10261, 13747, 14491, 15709, 18721, 19951, 23377, 31417, 31609] |
The first 20 super-Poulet numbers are: [341, 1387, 2047, 2701, 3277, 4033, 4369, 4681, 5461, 7957, 8321, 10261, 13747, 14491, 15709, 18721, 19951, 23377, 31417, 31609] |
||
Line 79: | Line 79: | ||
=={{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 119: | Line 119: | ||
<span style="color: #0000FF;">{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">),</span><span style="color: #000000;">x</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">})</span> |
<span style="color: #0000FF;">{</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">),</span><span style="color: #000000;">x</span><span style="color: #0000FF;">,</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">})</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 131: | Line 131: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="python">from sympy import isprime, divisors |
||
def is_super_Poulet(n): |
def is_super_Poulet(n): |
||
Line 143: | Line 143: | ||
print(f'The first super-Poulet number over 1 million is the {idx1m}th one, which is {val1m}') |
print(f'The first super-Poulet number over 1 million is the {idx1m}th one, which is {val1m}') |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
The first 20 super-Poulet numbers are: [341, 1387, 2047, 2701, 3277, 4033, 4369, 4681, 5461, 7957, 8321, 10261, 13747, 14491, 15709, 18721, 19951, 23377, 31417, 31609] |
The first 20 super-Poulet numbers are: [341, 1387, 2047, 2701, 3277, 4033, 4369, 4681, 5461, 7957, 8321, 10261, 13747, 14491, 15709, 18721, 19951, 23377, 31417, 31609] |
||
Line 151: | Line 151: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>use Prime::Factor; |
||
use Lingua::EN::Numbers; |
use Lingua::EN::Numbers; |
||
Line 163: | Line 163: | ||
my $index = @super-poulet.first: * > $threshold, :k; |
my $index = @super-poulet.first: * > $threshold, :k; |
||
say "{(1+$index).&ordinal-digit} super-Poulet number == " ~ @super-poulet[$index]., |
say "{(1+$index).&ordinal-digit} super-Poulet number == " ~ @super-poulet[$index]., |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First 20 super-Poulet numbers: |
<pre>First 20 super-Poulet numbers: |
||
Line 179: | Line 179: | ||
{{libheader|Wren-gmp}} |
{{libheader|Wren-gmp}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "./math" for Int |
||
import "./gmp" for Mpz |
import "./gmp" for Mpz |
||
import "./fmt" for Fmt |
import "./fmt" for Fmt |
||
Line 216: | Line 216: | ||
} |
} |
||
x = x + 2 |
x = x + 2 |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |