[Tutor] A better way for greatest common divisor
James Mills
prologic at shortcircuit.net.au
Fri Jul 30 04:10:20 CEST 2010
On Fri, Jul 30, 2010 at 11:47 AM, David Hutto <smokefloat at gmail.com> wrote:
> This is basically to get feedback, on a better way to show the
> greatest common divisor in fraction, in order to reduce it fully, than
> the one I've come up with. I'm sure there are better ways, so if you
> have simpler method, or critique of what I've done, let me know.
[snip]
I have a far simpler solution:
>>> from tools import gcd
>>> gcd(20, 5)
5
>>>
def gcd(a, b):
while b != 0:
(a, b) = (b, a%b)
return a
cheers
James
--
-- James Mills
--
-- "Problems are solved by method"
More information about the Tutor
mailing list