Erdős–Woods numbers: Difference between revisions

Content added Content deleted
(added Raku programming solution)
m (syntax highlighting fixup automation)
Line 33: Line 33:
=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Python}}
{{trans|Python}}
<lang julia>""" modified from https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin/ """
<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()
</lang>{{out}} Same as Wren example.
</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
<!--<lang Phix>(phixonline)-->
<!--<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>
<!--</lang>-->
<!--</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.
<lang python>""" modified from https://codegolf.stackexchange.com/questions/230509/find-the-erd%C5%91s-woods-origin/ """
<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
</lang>{{out}}Same as Wren example.
</syntaxhighlight>{{out}}Same as Wren example.


=={{header|Raku}}==
=={{header|Raku}}==
{{trans|Wren}}
{{trans|Wren}}
{{trans|Julia}}
{{trans|Julia}}
<lang perl6># 20220308 Raku programming solution
<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 } }</lang>
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.
<lang ecmascript>import "./big" for BigInt
<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
}</lang>
}</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!
<lang ecmascript>import "./gmp" for Mpz
<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
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}