Jump to content

Euler's sum of powers conjecture: Difference between revisions

→‎{{header|Raku}}: superscript in code, sigil-less, no temp. var, remove superfluous brackets, consolidate short-circuit tests
(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:
=={{header|Raku}}==
(formerly Perl 6)
 
{{Works with|rakudo|2018.10}}
{{trans|Python}}<syntaxhighlight lang="raku" line>constant MAX = 250;
 
my %po5{Int};
my %sum2{Int};
 
(for 1..MAX).map: -> $\i {
%po5{$i**5i⁵} = $i;
for 1..MAX -> $\j {
%sum2{$i**5i⁵ + $j**5j⁵} = ($i, $j);
}
}
 
my @sk = %sum2po5.keys.sort;.race.map: -> \p {
for %po5sum2.keys.sort.race.map: -> $p\s {
for @sk - 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>
{{out}}
<pre>27⁵ + 84⁵ + 110⁵ + 133⁵ = 144⁵</pre>
 
 
----
=={{header|REXX}}==
=== fast computation ===
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.