More or less code in python?

Dave Angel davea at davea.name
Mon Mar 16 03:32:30 EDT 2015


On 03/15/2015 03:09 PM, jonas.thornvall at gmail.com wrote:
> Den söndag 15 mars 2015 kl. 20:01:36 UTC+1 skrev Paul Rubin:
>> jonas.thornvall at gmail.com writes:
>>> I though it would be interesting doing comparissons in timing adding
>>> massive digits in different bases. Especially in Python.
>>
>> Python has built-in bignums.  Try "print 2**500".
>
> I will try implement the common operators + - * / pow sqrt operators mod floor and and a generic parser taking arguments in any base.
>

Why on earth would you bother?  Use the int(x, base) to convert a string 
in an arbitrary base to an int.  Write a similar function to convert an 
int back into a string of the desired base.  Of course, your strings 
aren't in a standard form, so you'd have to do some work to get those 
instead.  Are you really intending to use a base beyond 36?

Then to add two numbers, use +     To multiply, use *, and so on.

Assuming Python 3.x of course.  if you're in Python 2, you'd use "long" 
rather than int.

-- 
DaveA



More information about the Python-list mailing list