TITLE: Can you get any natural number from 4 by performing given operations?
QUESTION [10 upvotes]: You can perform the following operations on numbers:

divide the number by 2,
add 0 or 4 at the end of the number.

Can you get any natural number from 4 by performing only these operations?
So far I have come up with this algorithm to get 4 from any natural number N by performing opposite operations (multiplying by 2, deleting 0 or 4 from the end of the number).

Check the last digit of N,
a. If it's 0 or 4, remove the last
digit.
b. If it's neither 0 nor 4, multiply
N by 2.

If N is not 4 go to Step 1.


The problem is I can't prove that this algorithm works for any natural number.

REPLY [7 votes]: The following program (in Asymptote, but the syntax is pretty much the same as in C and, I hope, the algorithm is self-explanatory) considers all remainders modulo $10^n$ and prints those for which the steps up to the moment when we remove all $n$ known digits do not allow to conclude that the number got smaller. The printouts for $n=1,2,3$ are as mentioned in the comment. For $n=4$ the program terminates without printing anything.
int n=4, M=10^n;

for(int k=0;k<M;++k)
{
int nn=n, MM=M, a=k;
real s=0;
while(nn>0 && s>=-0.0000000001)
{
if(a%10==4 || a%10==0) {a=quotient(a,10);--nn;s-=log(10); MM=quotient(MM,10);}
else {a=(a*2)%MM; s+=log(2);}
}
if(s>0) write(k);
}

pause();