## ## pptmod.pl ## ## Perl script to generate HTML tables of primitive pythagorean triples ## modulo a given prime ## ## Fred Curtis (fred@f2.org) 18 Oct 2000 ## use strict; if (scalar(@ARGV) != 1) { print STDERR "Usage: $0 \n"; exit(1); } my $modulus = $ARGV[0]; my $modulus2 = int($modulus / 2); my $found = { }; print < i
(mod $modulus) j
(mod $modulus) a=ij
(mod $modulus) 2b=(j2-i2)/2
(mod $modulus) 2c=(j2+i2)/2
(mod $modulus) END my $i; my $j; for ($i = 0; $i < $modulus; $i++) { for ($j = 0; $j < $modulus; $j++) { print < $i $j END if ($i == 0 && $j == 0) { print < Invalid, gcd(i,j)=$modulus END } else { my $a = ($i * $j) % $modulus; my $b2 = ($j * $j - $i * $i) % $modulus; $b2 = ($b2 + $modulus) % $modulus; my $c2 = ($j * $j + $i * $i) % $modulus; my $b = ($b2 % 2 == 0 ? $b2 / 2 : ($b2 + $modulus) / 2); my $c = ($c2 % 2 == 0 ? $c2 / 2 : ($c2 + $modulus) / 2); $found->{$a}{$b}{$c} = 1; print <$a $b2 (b=$b) $c2 (c=$c) END } print < END } } print < END print < Summary: Possible
values of a,b,c modulo $modulus a
(mod $modulus) b
(mod $modulus) c
(mod $modulus) END { my $x; my $y; my $z; foreach $x (sort {$a<=>$b} keys %{$found}) { foreach $y (sort {$a<=>$b} keys %{$found->{$x}}) { foreach $z (sort {$a<=>$b} keys %{$found->{$x}{$y}}) { print < $x $y $z END } } } } print < END