use strict; my $max = 50; my $c = 0; # 0,0 is the first point for (my $i = 0; $i <= $max; $i++) { #i is the x location of the first point for (my $j = 0; $j <= $max; $j++) { #j is the y location of the first point next if ($i == 0 && $j == 0); for (my $k = 0; $k <= $max; $k++) { for (my $l = 0; $l <= $max; $l++) { next if ($k == 0 && $l == 0); next if ($i == $k && $j == $l); my $len1_sqr = $i*$i + $j*$j; my $len2_sqr = $k*$k + $l*$l; my $d1 = abs($k - $i); my $d2 = abs($l - $j); my $len3_sqr = $d1*$d1 + $d2*$d2; # right triangles are defined by a^2 + b^2 = c^2 if (($len1_sqr + $len2_sqr) == ($len3_sqr) || ($len2_sqr + $len3_sqr) == ($len1_sqr) || ($len1_sqr + $len3_sqr) == ($len2_sqr)) { $c++; } } } } } print($c/2);