[issue8692] Use divide-and-conquer for faster factorials
Daniel Stutzbach
report at bugs.python.org
Thu May 13 23:13:35 CEST 2010
Daniel Stutzbach <daniel at stutzbachenterprises.com> added the comment:
Isn't it amazing how fast one can make incorrect code? ;-)
Here is a fixed version of my partial_product3, but now it is no faster than partial_product.
def partial_product3(j, i):
a = [l << 1 | 1 for l in range(j, i + 1)]
n = len(a)
while 1:
if n == 1:
return a[0]
half = n//2
for k in range(0,half):
a[k] = a[k*2] * a[k*2+1]
if n & 1:
a[half] = a[n-1]
n = half + 1
else:
n = half
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8692>
_______________________________________
More information about the Python-bugs-list
mailing list