Help finding a concise way to express this sequence of integers

44 Views Asked by At

I have some unknown function which is giving me the following pattern when applied to the integers 0 to 195:

0 -> 0

1 -> 1

2 -> 10

3 -> 100

4 to 12 -> 101 to 109

13 -> 11

14 -> 110

15 to 23 -> 111 to 119

24 -> 12

25 -> 120

26 to 34 -> 121 to 129

...

Because it can't go above 195, the sequence eventually does this:

something -> 19

something + 1 -> 190

191-195 as normal

2

20

21 to 29 as normal

3

30

31 to 39 as normal

etc, until all 195 numbers are counted. Both the left-hand side and right-hand side will eventually have a single copy of the integers from 0 to 195.

I can recognize the pattern going on, but I can't seem to write it in a concise mathematical way.

1

There are 1 best solutions below

0
On

Here is a recipe for deriving the next element $x_{n+1}$ from the $n$th element $x_n$:

  • If $n \le 1$ then $x_n=n$
  • If $2 \le x_n \le 19$ then $x_{n+1} = 10x_n$
  • If $20\le x_n\le 194$, then $x_{n+1}=x_n+1$ with trailing zeros removed
  • If $x_n=195$, then $x_{n+1}=20$

Not very elegant, I'm afraid, and if you want $x_n$ directly in terms of $n$, it would get even messier. But perhaps there's a pattern that I'm not seeing. (Where does $195$ come from, by the way?)