I'm trying to understand the algorithm to find self-number.

But I don't know what does C, k, j, b is mean at this formula. What's that? How do I understand and what should I assign to solve them?

# [Math] About Self Number, which is found by D. R. Kaprekar.

algorithmsnumber theorysequences-and-series

#### Related Solutions

for intuition look at the way they use factorial base for $e = \sum_{n=1}^\infty \frac{1}{n!}$ here, $\pi$ is similar but less simple.

`floor($cell/9)`

and `$cell % 9`

are just how (integer) quotient and remainder are calculated in programming language. The `$cell`

indices are arranged row by row. The row number can be obtained as a quotient and the column number can be obtained as a remainder.

Take the cell numbered $42$ as an example. By division, $$42 = 9\cdot4 + 6$$ hence the cell is located on the 4th row (0-based) and the 6th column (also 0-based).

The block number is just sightly more complicated. The first part, `floor(return_row($cell) / 3) * 3`

, first calculates the quotient of the row number divided by $3$. So rows $0$ to $2$ are in the first third, and $6$ to $8$ are in the last third. Then this "group of 3 rows" index is multiplied by $3$, because there are 3 blocks for each group of 3 rows.

The second part, `floor(return_col($cell) / 3)`

, again find the quotient of the column number divided by $3$.

Taking the same example of cell $42$, which is on row 4 and column 6. The row number $$4 = 3\cdot\color{red}1 + 1;\;\left\lfloor\frac43\right\rfloor = \color{red}1$$ the quotient $\color{red}1$ means the cell is on the 1st "group of 3 rows" (0-based). And the column number $$6 = 3\cdot\color{blue}2+0;\;\left\lfloor\frac63\right\rfloor = \color{blue}2$$ the quotient $\color{blue}2$ means the cell is on the 2nd "group of 3 columns" (also 0-based). Combining this two information, the block where cell $42$ is at is assigned a block index $$\color{red}1\cdot 3 + \color{blue}2 = 5$$

Again, take $42$ as an example:

$$\begin{array}{l|l|ccc|ccc|ccc|} \text{Row}&\text{Cells}&0&1&2&3&4&5&6&7&8\\ \hline 0&0-8&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc\\ 1&9-17&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc\\ 2&18-26&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc\\ \hline 3&27-35&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc\\ 4&36-44&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\color{red}\bigcirc&\cdots\\ \end{array}$$

Notice the red $\color{red}\bigcirc$ is the 43rd $\bigcirc$. Elementary division says $\lfloor42/9\rfloor=4$ gives how many complete groups of $9$ the $42$ black $\bigcirc$s can form:

$$\begin{array}{l|l|ccc|ccc|ccc|} \text{Row}&\text{Cells}&0&1&2&3&4&5&6&7&8\\ \hline \color{blue}0&0-8&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc\\ \color{green}1&9-17&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc\\ \color{blue}2&18-26&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc&\color{blue}\bigcirc\\ \hline \color{green}3&27-35&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc&\color{green}\bigcirc\\ 4&36-44&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\bigcirc&\color{red}\bigcirc&\cdots\\ \end{array}$$

And the remaining $42\bmod 9=6$ black $\bigcirc$s count how many columns are before the red $\color{red}\bigcirc$. Since the row number and column number are $0$-based, the quotient $4$ and the remainder $6$ also denote the row and column numbers respectively.

## Best Answer

The formula you refer to is a recurrence. It generates

some(not all) self-numbers. The first formula works in base 10, while the second works in base 2. The third generalizes to any base.$C_k$ refers to the $k^{th}$ generated self number ($C_1$ is the first, $C_2$ is the second, ..etc.). Let's use the first formula to generate some self-numbers:

$C_1 = 9$ (as written between brackets)

We get $C_2$ by replacing $k$ in the formula by 2. $C_2 = 8*10^{2-1} + C_{2-1} + 8 = 8*10 + C_1 + 8 = 8*10 + 9 + 8 = 97$ (by substituting $C_1 = 9$).

You continue in this way and you get infinitely many self-numbers (but not all). If you really insist on generating all self-numbers, you iterate over all natural numbers and apply the test on each, or you find a cleverer way of doing it..