Brent's variation of a factorization algorithm

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Dec 9 00:53:20 EST 2009


En Tue, 08 Dec 2009 15:51:29 -0300, MRAB <python at mrabarnett.plus.com>  
escribió:
> Gabriel Genellina wrote:
>> En Fri, 27 Nov 2009 12:36:29 -0300, n00m <n00m at narod.ru> escribió:
>>
>>> def gcd(x, y):
>>>     if y == 0:
>>>         return x
>>>     return gcd(y, x % y)
>>>
>>> def brent(n): ...
>>  A better place to publish this code would be the Python Cookbook:  
>> http://code.activestate.com
>>
> An iterative alternative is:
>
> def gcd(x, y):
>      while y != 0:
>          x, y = y, x % y
>      return x

(note that the interesting part was the snipped code, the brent()  
function...)

-- 
Gabriel Genellina




More information about the Python-list mailing list