#!/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)); } }