I cannot test due to a shell/BOM carton error so this is a blind solution for the pythagorean-triplet :
sub triplets_with_sum {
my ($sum) = @_;
my @solutions;
for my $a ( 1 .. $sum ) {
my $numerator = 2*$a**2 + $sum**2 - 2*$sum*$a;
my $denominator = 2*( $sum - $a );
if ( $denominator > 0 and $numerator % $denominator == 0 ) {
my $c = $numerator / $denominator;
my $b = $sum - $a - $c;
push @solutions, [ $a, $b, $c ] if $b > $a;
}
}
return [ @solutions ];
}
--
$ carton install
XXX/.nix-profile/bin/carton: line 2: use: command not found
XXX/.nix-profile/bin/carton: line 3: use: command not found
XXX/.nix-profile/bin/carton: line 4: use: command not found
XXX/.nix-profile/bin/carton: line 6: syntax error near unexpected token `('
XXX/.nix-profile/bin/carton: line 6: `exit Carton::CLI->new->run(@ARGV);'
I cannot test due to a shell/BOM
carton
error so this is a blind solution for the pythagorean-triplet :--