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));
}
}



Replies are listed 'Best First'.  

Re: pythagorean triples
by Scott7477 (Chaplain) on Apr 24, 2006 at 03:37 UTC  
Re: pythagorean triples
by chas (Priest) on Apr 24, 2006 at 03:16 UTC  
by thor (Priest) on Apr 24, 2006 at 03:50 UTC  
by chas (Priest) on Apr 24, 2006 at 04:36 UTC  
by jgamble (Pilgrim) on Apr 24, 2006 at 21:21 UTC  
by jgamble (Pilgrim) on Apr 25, 2006 at 04:23 UTC 
Back to
Code Catacombs