Erdős–Woods numbers: Difference between revisions
Content added Content deleted
(added Raku programming solution) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 33: | Line 33: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia">""" modified from https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin/ """ |
||
using BitIntegers |
using BitIntegers |
||
Line 106: | Line 106: | ||
test_erdős_woods() |
test_erdős_woods() |
||
</ |
</syntaxhighlight>{{out}} Same as Wren example. |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 112: | Line 112: | ||
{{trans|Julia}} |
{{trans|Julia}} |
||
Using flag arrays instead of bigint bitfields |
Using flag arrays instead of bigint bitfields |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> <span style="color: #000080;font-style:italic;">-- takes about 47s (of blank screen) though, also note the line |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> <span style="color: #000080;font-style:italic;">-- takes about 47s (of blank screen) though, also note the line |
||
-- below which triggered an unexpected violation on desktop/Phix |
-- below which triggered an unexpected violation on desktop/Phix |
||
Line 207: | Line 207: | ||
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> |
<span style="color: #000000;">k</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}}Same as Wren example. |
{{out}}Same as Wren example. |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Original author credit to the Stackexchange website user ovs, who in turn credits user xash. |
Original author credit to the Stackexchange website user ovs, who in turn credits user xash. |
||
< |
<syntaxhighlight lang="python">""" modified from https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin/ """ |
||
def erdős_woods(n): |
def erdős_woods(n): |
||
Line 274: | Line 274: | ||
COUNT += 1 |
COUNT += 1 |
||
K += 1 |
K += 1 |
||
</ |
</syntaxhighlight>{{out}}Same as Wren example. |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
<lang |
<syntaxhighlight lang="raku" line># 20220308 Raku programming solution |
||
sub invmod($n, $modulo) { # rosettacode.org/wiki/Modular_inverse#Raku |
sub invmod($n, $modulo) { # rosettacode.org/wiki/Modular_inverse#Raku |
||
Line 343: | Line 343: | ||
say "The first 20 Erdős–Woods numbers and their minimum interval start values are:"; |
say "The first 20 Erdős–Woods numbers and their minimum interval start values are:"; |
||
for (16..116) { if (my $ew = ew $_) > 0 { printf "%3d -> %d\n",$_,$ew } }</ |
for (16..116) { if (my $ew = ew $_) > 0 { printf "%3d -> %d\n",$_,$ew } }</syntaxhighlight> |
||
{{out}}Same as Wren example. |
{{out}}Same as Wren example. |
||
Line 355: | Line 355: | ||
I ended up translating the Python 3.8 code (the more readable version) [https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin here], 6th post down, and found the first 20 E-W numbers in around 93 seconds. Much slower than Python which has arbitrary precision numerics built-in nowadays but acceptable for Wren. |
I ended up translating the Python 3.8 code (the more readable version) [https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin here], 6th post down, and found the first 20 E-W numbers in around 93 seconds. Much slower than Python which has arbitrary precision numerics built-in nowadays but acceptable for Wren. |
||
< |
<syntaxhighlight lang="ecmascript">import "./big" for BigInt |
||
import "./fmt" for Conv, Fmt |
import "./fmt" for Conv, Fmt |
||
import "./sort" for Sort |
import "./sort" for Sort |
||
Line 445: | Line 445: | ||
} |
} |
||
k = k + 1 |
k = k + 1 |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 475: | Line 475: | ||
{{libheader|Wren-gmp}} |
{{libheader|Wren-gmp}} |
||
Takes about 15.4 seconds which is significantly faster than Wren-cli, but still nowhere near as fast as the Python version - a majestic 1.2 seconds! |
Takes about 15.4 seconds which is significantly faster than Wren-cli, but still nowhere near as fast as the Python version - a majestic 1.2 seconds! |
||
< |
<syntaxhighlight lang="ecmascript">import "./gmp" for Mpz |
||
import "./fmt" for Conv, Fmt |
import "./fmt" for Conv, Fmt |
||
import "./sort" for Sort |
import "./sort" for Sort |
||
Line 566: | Line 566: | ||
} |
} |
||
k = k + 1 |
k = k + 1 |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |