way to calculate 2**1000 without expanding it?

Arnaud Delobelle arnodel at gmail.com
Fri Sep 16 16:57:12 EDT 2011


On 16 September 2011 21:20, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Fri, Sep 16, 2011 at 2:17 PM, Arnaud Delobelle <arnodel at gmail.com> wrote:
>> Ah go on, let's make a codegolf contest out of it.
>> My entry:
>>
>>>>> sum(map(int,str(2**1000)))
>> 1366
>
> That is exactly what mine was.
>

Slightly longer:

>>> eval("+".join(str(2**1000)))
1366

This looks like a winner but I cheated (the result depends on the
state of the interpreter):

>>> eval("+".join(`2**1000`))
1366

-- 
Arnaud



More information about the Python-list mailing list