sourcecode
Pete_I
<code>
#!/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));
}
}
</code>
calculates pythagorean triples<br />
<br />
explanation:
a pythagorean triple is a set of nonzero integers that make the pythagorean theorem return true when they're plugged in.<br /><br />
3,4,5 is the first triple.<br />
sqrt((3)**2 + (4)**2) = 25<br />
sqrt(9 + 16) = 25<br />
sqrt(25) == 5<br /><br />
I've got no idea what uses this could have, but I thought it was interesting.<br />
it looked cleaner at the beginning, but map{} and for(a..b) had big memory problems.<br />If you find a use for it, i'd like to know. Enjoy :)
Miscellaneous
