Count the number of digits of an integer
There are many ways to do so. The easiest way in Python consists on converting the number to string and returning the size of the string. It is simple but not necessary useful as building block for other problems.
It is possible to make this count using logarithm. The logarithm is the inverse function to exponentiation. Given a number \(x\) such that \(x=b^y\). Then, \(\log_b(x)=y\). Note that non-negative integer can be expressed as a power of \(10\) (or any other non-negative integer). So, we can count the number of digits of an integer using the following code.