Alright, get ready for today’s challenge. This one is also an easy one.
You know how books are marked, well yeah, they have numbers that represent pages. Your task is to ask for a number of pages there are in a book and the program should return how many digits was used to mark the book.
Example:

digity(10) => 11 #Explanation: The pages are 1,2,3,4,5,6,7,8,9,10. If you count there are 11 digits :P
digity(785) => 2247 #This would take me a long time, so no explanation

Hi @nikif99
You can directly return result fromNepToLog10 procedure. There is no need to use do-result function.
Also it will be nice if you can wrap all blocks in a procedure.

I cannot officially participate in this Daily Challenge anymore, and I’m aware of that. Still, I found the question elegantly mesmerizing. I have finally finished my own solution. Before I go on, I’d like to point out the fact that every solution in this thread so far uses iteration on the input to arrive on the answer. While this is an effective solution (and an easy one as well), it gets inefficient over larger inputs. Thus my single design goal was to achieve an answer without iterating on the input itself.

Here is what you all have done so far:

Iterating to the input

def digdig(pN):
digiNum = 0
for i in range(1, pN + 1):
digiNum = digiNum + len(str(i))
return(digiNum)

Clearly, if the algorithm iterates n times for an input of length m, for any input of length m+1, the algorithm has to iterate approximately 10n times.

Here is what I did:

Iterating over the number of digits in the input

def dugdug(pN):
digiNum = 0
for i in range(1, len(str(pN)) + 1):
if i != len(str(pN)):
digiNum += (int(("9"+(i-1)*"0"))*i)
else:
digiNum += ((((int(pN))//(10**(i-1)))-1)*(10**(i-1))+((int(pN))%(10**(i-1))+1))*i
return(digiNum)