Euler's sum of powers conjecture: Difference between revisions

Content added Content deleted
(changing formatting in the intro)
(→‎{{header|Raku}}: superscript in code, sigil-less, no temp. var, remove superfluous brackets, consolidate short-circuit tests)
Line 3,521: Line 3,521:
=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)

{{Works with|rakudo|2018.10}}
{{trans|Python}}<syntaxhighlight lang="raku" line>constant MAX = 250;
{{trans|Python}}<syntaxhighlight lang="raku" line>constant MAX = 250;


my %po5{Int};
my %po5{Int};
my %sum2{Int};
my %sum2{Int};


(1..MAX).map: -> $i {
for 1..MAX -> \i {
%po5{$i**5} = $i;
%po5{i⁵} = i;
for 1..MAX -> $j {
for 1..MAX -> \j {
%sum2{$i**5 + $j**5} = ($i, $j);
%sum2{i⁵ + j⁵} = i, j;
}
}
}
}


my @sk = %sum2.keys.sort;
%po5.keys.sort.race.map: -> \p {
%po5.keys.sort.race.map: -> $p {
for %sum2.keys.sort -> \s {
for @sk -> $s {
if p > s and %sum2{p - s} {
say ((sort |%sum2{s},|%sum2{p-s}) X~ '⁵').join(' + '), " = %po5{p}", "⁵" and exit
next if $p <= $s;
if %sum2{$p - $s} {
say ((sort |%sum2{$s}[],|%sum2{$p-$s}[]) X~ '⁵').join(' + ') ~ " = %po5{$p}" ~ "⁵";
exit;
}
}
}
}
}</syntaxhighlight>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>27⁵ + 84⁵ + 110⁵ + 133⁵ = 144⁵</pre>
<pre>27⁵ + 84⁵ + 110⁵ + 133⁵ = 144⁵</pre>



----
=={{header|REXX}}==
=={{header|REXX}}==
=== fast computation ===
=== fast computation ===