GCD in standard library?
lynx
none at of.your.business
Fri Mar 14 00:19:39 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?
--
PGP/GnuPG key (ID 1024D/3AC87BD1) available from keyservers everywhere
Key fingerprint = FA8D 5EA4 E7DC 84B3 64BC 410C 7AEE 54CD 3AC8 7BD1
"...if you can fill the unforgiving minute
with sixty seconds' worth of distance run..."
More information about the Python-list
mailing list