way to calculate 2**1000 without expanding it?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Sep 16 22:17:05 EDT 2011


Arnaud Delobelle wrote:

> Ah go on, let's make a codegolf contest out of it.
> My entry:
> 
>>>> sum(map(int,str(2**1000)))
> 1366


Time for some obfuscated Python!

b = (16,13624)
for i in range(23, 42, 3):
    b = (b[0]*b[0], b[1]+1024)

for j in range(12345, 8929, -7):
    b = (b[0]+b[0], b[1]-3)

while b > (0,9876):
    b = tuple((lambda a,b: map(lambda a,b:a+b, a,b))
        ((lambda a,b: map(lambda a,b:a*b, a,b))
        (b,(0,1)), (lambda a,b: map(lambda a,b:a-b, a,b))
        (divmod(b[0],10),(0,64))))

print b[1]



-- 
Steven




More information about the Python-list mailing list