GCD in standard library?
Raymond Hettinger
vze4rx4y at verizon.net
Fri Mar 14 01:01:38 EST 2003
> On Wed, 12 Mar 2003 20:08:18 +0000, Steven Taschuk wrote:
> > Quoth Blake Garretson:
>
> >> def gcd(x,y):
> >> if x % y == 0: return y
> >> else: return gcd(y,x%y)
>
> > I for one haven't needed this in Python yet, but if I did I'd do
> > it this way:
> > def gcd(a, b):
> > while b:
> > a, b = b, a % b
> > return abs(a)
> > which (1) avoids the unnecessary recursion,
>
> i suppose it's pointless to ask for python to become a properly
> tail-recursive language then?
Depends on who you ask.
http://www.stackless.com
Raymond Hettinger
More information about the Python-list
mailing list