sub gen_triangles { my $max = shift || 10; my @set; my($x,$y,$z)=(1,1,1); while($z<=$max && $x<=$max){ push @set, [$z, $y, $x] if $x**2 == $y**2 + $z**2; if($y>$z){$z++}else{if($x>$y){$y++;$z=1}else{$x++;$y=$z=1}} } return \@set; }