source code for "files/pe/pe_039.pl"
return to portfolio
- #!/usr/bin/perl
- use strict;
- use warnings;
- use euler;
- my $largest = 0;
- my $count = 0;
- my ($solution);
- for my $p (1..1000) {
- $count = 0;
- for my $a (1..$p/4) { # by triangle inequality
- my $b = $p*($p-2*$a)/(2*($p-$a)); # by solving system of equations
- my $c = sqrt($a**2+$b**2); # by pythagorean theorem
- $count++ if $c == int $c; # because we want integer solutions only
- }
- if ($largest < $count) {
- $largest = $count;
- $solution = $p;
- }
- }
- print $largest, ' ', $solution;