in reply to Pythagorean's theorem
withfor ($b=1; $b<$max; $b++) {
for ($b=$a; $b<$max; $b++) {
You might also want to avoid your third embedded loop. It doesn't matter much if you do pythagoras.pl 10, but pythagoras.pl 1000 is sloooooooow.
You already know a and b, so you just need to test if a^2 + b^2 is a perfect square. For that you probably need one of the Math modules.
Update
Doh! You can just do **(1/2) to get the square root. Back to maths class for me. Although, will integer handling bite you in the ass if you just do
my $h = ($a**2 + $b**2) ** (1/2); if ($h == int $h) { print "$a $b $h is a winner\n"; }
? I don't know. Answers on a postcard.
dave hj~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Pythagorean's theorem
by fuzzyping (Chaplain) on Feb 27, 2002 at 17:16 UTC |