in reply to Finding the greatest common divisor

Great heavens, don't do all that. You don't have to find all the divisors just to find the greatest common divisor. Just use this:

sub gcd { my ($a, $b) = @_; ($a,$b) = ($b,$a) if $a > $b; while ($a) { ($a, $b) = ($b % $a, $a); } return $b; }
This algorithm was invented by Euclid about 2200 years ago.

--
Mark Dominus
Perl Paraphernalia

Replies are listed 'Best First'.
Re (tilly) 2: Finding the greatest common divisor
by tilly (Archbishop) on Sep 04, 2001 at 00:09 UTC
    Actually Euclid's Elements were written about 2300 years ago. But we don't know whether or not he originated it. It is true that the first written record that we have of it is in Proposition VII.2. However we have no particular reason to believe that Euclid invented most of his results. All that we know is that he wrote the textbook.

    And the algorithm was of practical use at the time for converting money from one currency to another. So for all we know it may have been in wide-spread use prior to Euclid. Or it might have been used by the Phoenicians from whom we have very few records, but who are known to have engaged in trade and were purportedly good with numbers. (But who were, of course, not on such good terms with Rome...)

    The truth is that we simply don't know who came up with the results in Euclid's textbook.

    An incidental piece of trivia. The Elements of Euclid is the single most often translated and published non-religious work in history. (The most often translated and published work is, of course, the Bible.)