On 10.04.2011 05:37, John Cremona wrote:
> The easiest way to get the number of digits of a positive integer n is
> len(str(n)) or even n.ndigits() !
> 
> So
> 
> sage: N=10^6
> sage: sum([n.ndigits() for n in srange(1,N+1)])
> 5888896
> 
> solves your problem for all integers up to a million.  This is
> obviously not the fastest way though!
> 
> John
> 
> On Apr 9, 6:53 pm, Alex Howard <ajhowar...@gmail.com> wrote:
>> Hi,
>> I'm trying to create a function which outputs the number of digits you'd 
>> have to
>> write down to write every integer from 1 up to the input value.
>> Having defined x and z as variables I used this at one point...
>>
>> z(x)=((int(log(x,10)))+1)*(1+x-((10^int(log(x,10)))))
>>
>> It gets rejected as does using the 'floor' function. At one point i managed 
>> to
>> make it output
>>
>> z(3143) = ((floor(log(3143,10)))+1)*(1+3143-((10^floor(log(3143,10)))))
>>
>> as an expression involving logs but I can't find a way to output a number. 
>> any
>> help would be great.
>>
>> Thanks
> 

Hi,

it works if you use a python function:

def z(x):
    return ((floor(log(x,10)))+1)*(1+x-((10^floor(log(x,10)))))

for some reason it does not evaluate floor when evaluating symbolic
functions.

Adrian

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to