Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
You rule Tilly!
I had to point out the mod operator in this function: sub gcd { my ($n, $m) = @_; while ($m) { my $k = $n % $m; ($n, $m) = ($m, $k); } return $n; }. . . particularly the use of the mod operator. I remember reading Robert Sedgewick's Mastering Algorithms in C++ and really getting a kick out of the first example - Euclide's greatest common denominator formula. At first, Sedgewick implemented it with the division operator: my $k = $n / $m;Then he explained that replacing the / operator with the % operator results in about 75% less iterations through the while loop. Incredible. Jeff In reply to (jeffa) Re: Continued Fractions
by jeffa
|
|