Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created November 28, 2022 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtetsuji/b5ca2578ff55b183da753e31399452eb to your computer and use it in GitHub Desktop.
Save xtetsuji/b5ca2578ff55b183da753e31399452eb to your computer and use it in GitHub Desktop.
square-sum-1128.pl
2^2 + 10^2 + 32^2 = 1128
2^2 + 32^2 + 10^2 = 1128
10^2 + 2^2 + 32^2 = 1128
10^2 + 32^2 + 2^2 = 1128
14^2 + 16^2 + 26^2 = 1128
14^2 + 26^2 + 16^2 = 1128
16^2 + 14^2 + 26^2 = 1128
16^2 + 26^2 + 14^2 = 1128
26^2 + 14^2 + 16^2 = 1128
26^2 + 16^2 + 14^2 = 1128
32^2 + 2^2 + 10^2 = 1128
32^2 + 10^2 + 2^2 = 1128
#!/usr/bin/env perl
use strict;
use warnings;
my $MAX_NUMBER = 1128;
my $BIRTHDAY = 1128;
for my $x (1..$MAX_NUMBER) {
for my $y (1..$MAX_NUMBER) {
for my $z (1..$MAX_NUMBER) {
my $sum = $x**2 + $y**2 + $z**2;
if ( $sum == $BIRTHDAY ) {
print "$x^2 + $y^2 + $z^2 = $BIRTHDAY\n";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment