Category:  Miscellaneous 
Author/Contact Info   
Description:  calculates pythagorean triples explanation: a pythagorean triple is a set of nonzero integers that make the pythagorean theorem return true when they're plugged in. 3,4,5 is the first triple. sqrt((3)**2 + (4)**2) = 25 sqrt(9 + 16) = 25 sqrt(25) == 5 I've got no idea what uses this could have, but I thought it was interesting. it looked cleaner at the beginning, but map{} and for(a..b) had big memory problems. If you find a use for it, i'd like to know. Enjoy :) 
#!/usr/bin/perl
#generate pythagorean triples until n = ARGV[1]
#based on this: http://www.math.uic.edu/~fields/puzzle/triples.html
#a, b, c = n^2  m^2, 2*m*n, n^2 + m^2
my($m, $n, $end);
$end = $ARGV[0]  5;
for($n = 1; $n <= $end; $n++) {
for($m = 1; $m < $n; $m++) {
printf("%d,%d,%d\n", ($n * $n  $m * $m), (2 * $m * $n), ($n * $n +
+$m * $m));
}
}

Back to
Code Catacombs