Decimals -> Fraction strings, my solution

François Pinard pinard at iro.umontreal.ca
Tue May 16 19:04:56 EDT 2000


kain at cableadmin.com (Scott) writes:

> def gcd (numer, denom):
>     """Return the greatest common denominator of two numbers"""
>     if denom % numer == 0:
>         return numer

>     p1 = plist (numer)
>     p2 = plist (denom)
>     p1.reverse ()
>     for x in p1:
>         if x in p2:
>             return x

Hi, people.  I prefer the following definition for GCD:

def gcd(a, b):
    while a:
        a, b = b % a, a
    return b

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list