Skip to main content
5 of 7
deleted 4 characters in body

What's this constructed number's starter?

A number of programming languages construct large integers through 'concatenating' the digit to the end of the existing number. For example, Labyrinth, or Adapt. By concatenating the digit to the end, I mean that, if the existing number is \$45\$, and the digit is \$7\$, the result number is \$457\:(45 \times 10 + 7)\$.

A concstructed number is a number that can be built this way through the use of the multiples of single digit numbers: \$1, 2, 3, 4, 5, 6, 7, 8, 9\$ A.K.A an element in one of these 9 sequences:

$$1, 12, 123, 1234, 12345, \: \dots$$ $$2, 24, 246, 2468, 24690, \: \dots$$ $$3, 36, 369, 3702, 37035, \: \dots$$ $$4, 48, 492, 4936, 49380, \: \dots$$ $$5, 60, 615, 6170, 61725, \: \dots$$ $$6, 72, 738, 7404, 74070, \: \dots$$ $$7, 84, 861, 8638, 86415, \: \dots$$ $$8, 96, 984, 9872, 98760, \: \dots$$ $$9, 108, 1107, 11106, 111105, \: \dots$$

To provide an example of how the sequences are constructed, here's how the sequence for \$a = 3\$ in constructed:

$$\begin{align} u_1 = && a = && 3 & = 3\\ u_2 = && 10 \times u_1 + 2 \times a = && 30 + 6 & = 36 \\ u_3 = && 10 \times u_2 + 3 \times a = && 360 + 9 & = 369 \\ u_4 = && 10 \times u_3 + 4 \times a = && 3690 + 12 & = 3702 \\ u_5 = && 10 \times u_4 + 5 \times a = && 37020 + 15 & = 37035 \\ u_6 = && 10 \times u_5 + 6 \times a = && 370350 + 18 & = 370368 \\ \end{align}$$ $$\vdots$$

It may still not be clear how these sequences are constructed, so here are two different ways to understand them:

  • Each sequence starts from the single digit. The next term is found by taking the next multiple of that digit, multiplying the previous term by \$10\$ and adding the multiple. In sequence terms:

    $$u_n = 10 \times u_{n-1} + n \times a, \: \: u_1 = a$$

    where \$a\$ is a single digit (\$1\$ through \$9\$)


  • Each of the \$9\$ elements at any point in the sequence (take \$n = 3\$ for instance) are the multiples of \$123\dots\$ from \$1\$ to \$9\$, where \$123\dots\$ is constructed by \$u_{n+1} = 10 \times u_n + n\$ \$(1, 12, 123, \dots, 123456789, 1234567900, 12345679011)\$

    So the first values are \$1 \times 1, 2, 3, \dots, 8, 9\$, the second are \$12 \times 1, 2, 3, \dots, 8, 9\$, the third \$123 \times 1, 2, 3, \dots, 8, 9\$, etc.

Your task is to take a constructed number as input and to output the initial digit used to construct it. You can assume the input will always be a constructed number, and will be greater than \$0\$. It may be a single digit, which maps back to itself.

You may take input in any reasonable manner, including as a list of digits, as a string etc. It is acceptable (though not recommended) to take input in unary, or any other base of your choosing.

This is a so the shortest code wins!


Sandbox

  • Is this clear enough? Is it easily understand what a constructed number is?
  • Tags are and . Any other suggestions?
  • Is this a duplicate?
  • Any further feedback?

9 bytes in Jelly (2ee5cc40cffb0335f1a4f922a98b2b49)