How to resolve the algorithm Euler's sum of powers conjecture step by step in the Perl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Euler's sum of powers conjecture step by step in the Perl programming language
Table of Contents
Problem Statement
There is a conjecture in mathematics that held for over two hundred years before it was disproved by the finding of a counterexample in 1966 by Lander and Parkin. This conjecture is called Euler's sum of powers conjecture and can be stated as such: In 1966, Leon J. Lander and Thomas R. Parkin used a brute-force search on a CDC 6600 computer restricting numbers to those less than 250. The task consists in writing a program to search for an integer solution of
x
0
5
x
1
5
x
2
5
x
3
5
=
y
5
{\displaystyle x_{0}^{5}+x_{1}^{5}+x_{2}^{5}+x_{3}^{5}=y^{5}}
where all
x
i
{\displaystyle x_{i}}
and
y
{\displaystyle y}
are distinct integers between 0 and 250 (exclusive). Show an answer here. Related tasks are:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Euler's sum of powers conjecture step by step in the Perl programming language
Source code in the perl programming language
use constant MAX => 250;
my @p5 = (0,map { $_**5 } 1 .. MAX-1);
my $s = 0;
my %p5 = map { $_ => $s++ } @p5;
for my $x0 (1..MAX-1) {
for my $x1 (1..$x0-1) {
for my $x2 (1..$x1-1) {
for my $x3 (1..$x2-1) {
my $sum = $p5[$x0] + $p5[$x1] + $p5[$x2] + $p5[$x3];
die "$x3 $x2 $x1 $x0 $p5{$sum}\n" if exists $p5{$sum};
}
}
}
}
use constant MAX => 250;
my @p5 = (0,map { $_**5 } 1 .. MAX-1);
my $rs = 5;
for my $x0 (1..MAX-1) {
for my $x1 (1..$x0-1) {
for my $x2 (1..$x1-1) {
my $s2 = $p5[$x0] + $p5[$x1] + $p5[$x2];
$rs-- while $rs > 0 && $p5[$rs] > $s2;
for (my $x3 = 1; $x3 < $x2; $x3++) {
my $e30 = ($x0 + $x1 + $x2 + $x3 - $rs) % 30;
$x3 += (30-$e30) if $e30;
last if $x3 >= $x2;
my $sum = $s2 + $p5[$x3];
$rs++ while $rs < MAX-1 && $p5[$rs] < $sum;
die "$x3 $x2 $x1 $x0 $rs\n" if $p5[$rs] == $sum;
}
}
}
}
You may also check:How to resolve the algorithm Harshad or Niven series step by step in the COBOL programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Forth programming language
You may also check:How to resolve the algorithm Visualize a tree step by step in the Prolog programming language
You may also check:How to resolve the algorithm Super-Poulet numbers step by step in the Wren programming language
You may also check:How to resolve the algorithm Machine code step by step in the Racket programming language