Define function that tells me if an integer is a zero_special

62 Views Asked by At

I'd like to define $zeroes(n)$ as the number of zeros in the decimal expansion of the integer $n$. A number $n$ is zero_special if $$zeroes(n) > zeroes(n-1)$$ Can I write a function that determines whether $n$ is zero_special? What does "the decimal explansion of the integer $n$" mean?

1

There are 1 best solutions below

1
On

In the number $100$ you see two zeroes, so $\mathrm{zeroes}(100)=2$. In the number $5$ you see no zeroes, so $\mathrm{zeroes}(5)=0$. The function $\mathrm{zeroes}$ simply counts the number of zeroes you see when you write the number down. A number is therefore zero-special if, when writing it down, you see more numbers than when you write your original number minus one.

For example, if you write $10$, you see one $0$. If you write $9$ there is no $0$, so $10$ is zero-special. You can check yourself that the numbers $20,...,90$ are also zero special and that no other two-digit numbers are.

I claim that if the number has more than two digits, it is zero special if and only if it is a multiple of 100, i.e. if its decimal expansion ends in 00.Let $a$ be an integer and let $a=a_{n}a_{n-1}...a_{1}a_{0}$, with $0\leq a_{i}\leq 9$ for all $i$, be its decimal expansion. If $a_{0}>0$, then the decimal expansion of $a-1$ is $a-1=a_{n}a_{n-1}...a_{1}(a_{0}-1)$. This either has the same number of zeroes as for $0$ or it even has one more, so $a$ is not zero special.

If $a_{0}=0$ but $a_{1}> 0$, then the decimal expansion of $a-1$ becomes $a-1=a_{n}a_{n-1}...(a_{1}-1)9$. Again, the number of zeroes in this expansion is either the same as for $a$ (if $a_{1}=1$) or it is one higher.

If $a_{0}=0=a_{1}$ and $a_{2}>0$, then the decimal expansion of $a-1$ becomes $a-1=a_{n}a_{n-1}...(a_{2}-1)99$. Now the number of zeroes in the decimal expansion of $a-1$ is strictly lower than that in the decimal expansion of $a$. If we drop the condition that $a_{2}>0$, we simply replace more $0$'s with $9$'s in the decimal expansion of $a-1$. The number of zeroes in the decimal expansion of $a-1$ is again smaller than that in the decimal expansion of $a$.