I have a friend ~200 years old mathematician who has forgotten some digits and now he counts things in very strange manner: when he is going to count the $n$-th thing and $n$ contains a digit he cannot pronounce and write (because of his senile memory - oh, poor man) he skip $n$ and tries to think of next smallest number after $n$ that does not contain the digit.
Poor old mathematician who forgot digits 0, 2, 5, 6, 7 counts:
1, 3, 4, 8, 9, 11, 13, 14, 18, 19, 31, 33, 34, 38, 39, 41, 43, 44, 48, 49, 81, 83, 84, 88, 89, 91, 93, 94, 98, 99, 111, 113, ...
He claims that second thing is third, third is fourth, fourth is eighth and do not see any problems at all. However I do have a problem now, that is keep bothering me:
How do I easily name the $n$-th thing in his counting system?
Generally,
Natural numbers that contain certain digits are dropped from $\mathbb{N}$. What is a formula for the $n$th number of this sequence?
Let's look at a plot of the numbers my friend still remember:
$\hskip0.75in$
that looks like a random hops at the first glance, but take the difference between $\left(n+1\right)$th and $n$th element and you'll get this:
$\hskip0.75in$
hence the second part of the question's title. I believe that this is a some fractal structure and therefore there exist a recurrence relation that is a solution to my problem.
Firstly, I've tried to examine a very simple example: Base 3; digits allowed: 0, 2:
0, 2, 20, 22, 200, 202, 220, 222, 2000, 2002, 2020, 2022, 2200, 2202, 2220, 2222, ...
adjacent differences:
2, 11, 2, 101, 2, 11, 2, 1001, 2, 11, 2, 101, 2, 11, 2, ...
There are some "oscillations" seen...
$\hskip0.75in$
Notation:
Let $n$ be the number we want to get, $b$ - the base of numerical system, $D$ - set of digits allowed, then $N(D, b, n)$ - $n$th number in the sequence of numbers of base $b$ with only allowed digits $D$.
So far, I have only seen that $N(\{0,2\},3,n^3+1)=N(\{0,2\},3,n^3)+2$.
Help me, please (at least by small hints or advices) to deduce the relations that will help me to beat the problem and consequently help to reach a compromise between my friend and me. :)
Update
It may seem strange that I ask about generating sequences with some of them already found and even plotted. Indeed, I've already found an easy programming solution that uses combinations of digits to form those numbers and it's highly inefficient and not a matter of talk at this site at all. I'm asking about purely mathematical solution.
Update
I've just seen the sequence of adjacent differences from my example
Base 3; digits allowed: 0, 2 that looks like this (in decimal): $$\left\{\begin{cases} 1+3^0,\quad n\equiv 2^0-1\pmod {2^1}\\ 1+3^1,\quad n\equiv 2^1-1\pmod {2^2}\\ 1+3^2,\quad n\equiv 2^2-1\pmod {2^3}\\ \cdots\\ 1+3^p,\quad n\equiv 2^p-1\pmod{2^{p+1}}\\ \cdots \end{cases} \right\}_{n\ge0}$$ In other words, if $a(n)$ is a $n$th element of the sequence, then $$a(2^{p+1} n + 2^p - 1) = 1 + 3^p, \quad p \ge 0$$ UpdateUsing this ideas, I conclude that $$a(n)=\sum_{i=1}^\infty\frac{1}{2^i}\sum_{j=1}^{2^i}cos(j\,n\,π/2^{i-1})$$ Thus, $$N(\{0,2\},3,n)=N(\{0,2\},3,n-1)+1+3^\wedge(\sum_{i=1}^\infty\frac{1}{2^i}\sum_{j=1}^{2^i}cos(j\,n\,π/2^{i-1}))$$ But this particular solution does not enlighten me on a general solution.