in reply to Finding the greatest common divisor
This is an inelegant brute force approach:
This is O(n) in that the bigger the smaller number the longer this will take to run. For a more elegant approach use Euclid's recursive algorithm as suggested by larsen it is O(log $a * log $b) - ie so much more efficient it is not funny!:
print euclid(15000,1260); sub euclid { my( $a, $b ) = @_; return ($b) ? euclid( $b, $a % $b ) : $a; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|