[Question]
  [
A number of programming languages construct large integers through 'concatenating' the digit to the end of the existing number. For example, [Labyrinth](https://github.com/m-ender/labyrinth), or [Adapt](https://github.com/cairdcoinheringaahing/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 constructed 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$$
$$\begin{align}
u\_{33} = && 10 \times u\_{32} + 33 \times a = && 37\dots260 + 99 & = 37\dots359 \\
u\_{34} = && 10 \times u\_{33} + 34 \times a = && 37\dots359 + 102 & = 37\dots3692
\end{align}$$
$$\vdots$$
\$u\_{33}\$ and \$u\_{34}\$ included to demonstrate when \$n \times a \ge 100\$. A *lot* of digits dotted out for space.
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](https://en.wikipedia.org/wiki/Multiple_(mathematics)) 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, \dots)\$
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code wins!
## Test cases
```
       u_n        => a
 37035            => 3
 6172839506165    => 5
 5                => 5
 246913580244     => 2
 987654312        => 8
 61728395061720   => 5
 1111104          => 9
 11111103         => 9
 111111102        => 9
 2469134          => 2
 98760            => 8
 8641975308641962 => 7
```
or as two lists:
```
[37035, 6172839506165, 5, 246913580244, 987654312, 61728395061720, 1111104, 11111103, 111111102, 2469134, 98760, 8641975308641962]
[3, 5, 5, 2, 8, 5, 9, 9, 9, 2, 8, 7]
```
---
When I posted this challenge, I didn't realise it could be simplified so much by the method used in [Grimmy's answer](https://codegolf.stackexchange.com/a/191306/66833), and so therefore would be very interested in answers that take a more mathematical approach to solving this, rather than a 'digit' trick (Obviously all valid answers are equally valid, just what I'd be interested in seeing).
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~7~~ ~~5~~ 4 bytes
```
>9*н
```
[Try it online!](https://tio.run/##TYw7CsJQFET7WUVIKQr3f@9rkrUoWFhZCELArbkHd/QkJoXTzCnOzP1xvtyu/fVc5nE4TcM4L31qh8@7H7smqSM4pbQ5BYfDIRaN1YvEDK0y3JTlX0sh8BqyrZl0BybZD7YtocK4pSv9IAQMgcIQSBQamOoL "05AB1E – Try It Online")
```
>            # input + 1
 9*          # * 9
   н         # take the first digit
```
The \$(n-1)^{th}\$ term of the sequence starting with \$a\$ is \$\sum \_{i=1}^{n-1} a \times i \times 10^{i-1} = a \times \frac{(10^n - 1) / 9 - n}{9}\$. Multiply that by \$9\$ and add \$a\times n\$, and you get \$a \times \frac{10^n - 1}{9}\$, aka the digit \$a\$ repeated \$n\$ times. Turns out adding \$9\$ instead of \$a\times n\$ works for \$n=1\$, and for bigger \$n\$ the linear difference is negligible next to the exponential growth.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 5 bytes
```
^9*Eh
```
[Run and debug it](https://staxlang.xyz/#c=%5E9*Eh&i=+37035++++++++++%0A+6172839506165+++%0A+5+++++++++++++++%0A+246913580244++++%0A+987654312++++++++%0A+61728395061720+++%0A+1111104++++++++++%0A+11111103++++++++%0A+111111102++++++++%0A+2469134+++++++++%0A+98760+++++++++++%0A+8641975308641962+&a=1&m=2)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 7 bytes
```
§Ｉ×⁹⊕Ｎ⁰
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMOxxDMvJbVCwzmxuEQjJDM3tVjDUkfBMy@5KDU3Na8kNUXDM6@gtMSvNDcptUhDEwh0FAw0Na3//7cwMzG0NDc1NgAzzIz@65blAAA "Charcoal – Try It Online") Link is to verbose version of code. @Grimy's method of course. Here's a 27 byte mathematical approach:
```
ＮθＷ¬№Ｅχ×κ↨υχθ⊞υＬυＩ⌕Ｅχ×ι↨υχθ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05qrPCMzJ1VBwy@/RMM5vzSvRMM3sUDD0EBHISQzN7VYI1tHwSmxOFWjVEfB0EBTU1NHoRBIKgSUFmeAxHxS89JLgCxNoEkBRZlA7c6JxSUabpl5KWgGZWI1yPr/fwszE0NLc1NjAzDDzOi/blkOAA "Charcoal – Try It Online") Link is to verbose version of code. Crashes on invalid inputs. Explanation:
```
Ｎθ
```
Input the constructed number.
```
Ｗ¬№Ｅχ×κ↨υχθ
```
Interpret the list as a number in base 10, multiply by all numbers from `0` to `9`, and see whether the constructed number appears.
```
⊞υＬυ
```
Push the list's length to itself. The list therefore becomes of the form `[0, 1, 2, ..., n]`.
```
Ｉ⌕Ｅχ×ι↨υχθ
```
Recreate the constructed numbers but this time find and output the index at which the input number appeared.
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 6 bytes
```
)9*▒├Þ
```
[Try it online!](https://tio.run/##bY67DcJAEERzV@EUR/vf23JIgMAWCZVYiAjRDJ24kcN3Ts4WE63eaGdmOj9u1/t4yfkUw/Kal@f7@8mZHVj7Rp2hU@JQMLTqdDu/EhILZE1AIhuJ5KbCSH9inKAQLAJpYjbCB7AiOjS1T6UJdmuSCYYrQz2Mfg "MathGolf – Try It Online")
Unfortunately, there's no `head` operation in MathGolf, so I have to make do with `▒├Þ` to convert to string, pop from the left and discard all but the top of stack.
[Answer]
# [Labyrinth](https://github.com/m-ender/labyrinth), ~~28 22~~ 20 bytes
```
9 10/;!@
? _ :
)*"""
```
Applies the digit-based method described [by Grimy](https://codegolf.stackexchange.com/a/191306/53748) by repeated integer division by ten until zero is found.
**[Try it online!](https://tio.run/##y0lMqizKzCvJ@P/fUsHQQN9a0YHLXiFewYpLU0tJSQkoamFuZmpibGgEAA "Labyrinth – Try It Online")**
[Answer]
# [Python 3](https://docs.python.org/3/), 22 bytes
```
lambda i:str(-~i*9)[0]
```
[Try it online!](https://tio.run/##VY7NCoJQEIX3PsVAGw2D@bm/Qk9iLoyQLpSKuWnTq9@upouGs/hmOJwz43u@D73E7nyJj/Z5vbUQqtc85adPOPqixiZ2wwQBQg@1WBRdgiHLTrxGQyatSayMJ9EOWakSvLNGKyH@s1rGEmgZVBsQyk6EvMdsCcntjCJvteAKhpsqg3EK/Zx3eSiKLDvUsvYvLyT7Cn7X72Kb@AU "Python 3 – Try It Online")
Port of [Grimy](https://codegolf.stackexchange.com/users/6484/grimy)'s [05AB1E answer](https://codegolf.stackexchange.com/a/191306/87681)
---
# [Python 3](https://docs.python.org/3/), 72 bytes
```
f=lambda i,j=1,l=1,k=2:l*(i==j)or f(i,*(10*j+k*l,l+1,l,l+1,k+1)[i<j::2])
```
[Try it online!](https://tio.run/##VY5ND4IwDIbv/IolXhjs0I99MOJ@CeGgMcTBBGO8@Otxohxs2uZt8@Rt76/ndZl5XYeQTrfz5SSiGgOqlGsK1KaqjCGMcnmIoYyqKhGqsZ6qpFKdqa1PNcouHse2pV6uQ0ajiLPo2AEbJSw6atgbsGjzmJO09cimAdJaCd84azQj/aGOQAn8BOifQOBdIdBu83PIdGM1emcYNmGpbwtxf8T5WebXpSyKQ8fb/c8LGd@E3/O7cf36Bg "Python 3 – Try It Online")
### Explanation
Recursive function. Iterates over the sequence for each digit `l`, starting at `1`. If the input `i` is equal to the current iteration `j`, the corresponding digit `l` is returned. Else, if the current value `j` in the sequence exceeds the input value `i`, it will increment the digit `l` and start over. Argument `k` is used to increment the multiplication factor.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
‘×9DḢ
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw4zD0y1dHu5Y9P//fwszE0NLc1NjAzDDzAgA "Jelly – Try It Online")
Using [Grimy's approach](https://codegolf.stackexchange.com/a/191306/41024).
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-g`](https://codegolf.meta.stackexchange.com/a/14339/), ~~7~~ ~~6~~ 5 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
-1 byte thanks to Shaggy
Takes input as a string
```
i°U*9
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWc&code=abBVKjk&input=JzYxNzI4Mzk1MDYxNjUn) | [Test multiple inputs](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LW1S&header=cw&code=abBVKjk&footer=Vmc&input=IFsKIDM3MDM1ICAgICAgICAgIAogNjE3MjgzOTUwNjE2NSAgIAogNSAgICAgICAgICAgICAgIAogMjQ2OTEzNTgwMjQ0ICAgIAogOTg3NjU0MzEyICAgICAgICAKIDYxNzI4Mzk1MDYxNzIwICAgCiAxMTExMTA0ICAgICAgICAgIAogMTExMTExMDMgICAgICAgIAogMTExMTExMTAyICAgICAgICAKIDI0NjkxMzQgICAgICAgICAKIDk4NzYwICAgICAgICAgICAKIDg2NDE5NzUzMDg2NDE5NjIgCl0)
[Answer]
# Java 8, 23 bytes
```
n->(n*9+9+"").charAt(0)
```
Port of [*@Grimy*'s 05AB1E answer](https://codegolf.stackexchange.com/a/191306/52210), so make sure to upvote him!
[Try it online.](https://tio.run/##dZFNboMwEIX3OcWIlV0E8h8GFLVS92k2WVZduMQlpMQgMJGqKtseoEfsRaghREqK6oVlf/PGb/S8V0cV7LfvfVaqtoUnVZjPBUBhrG7eVKZhPVwBsp1qIENlZXIweOnYaeG21ipbZLAGA/fQm@ABmbvUT33Pw@HQ8mgRwf1ykNbda@mkU8exKrZwcG5oY5vC5M8voPDZyurWIh4THo0@E5A0ZglPIyKpjFbXlRsZEzKlPEoIE@JGlSaxjASn7J9HY0Zu9HRYRMwQJXzOKGHzIcRfe3INEiloGkecjAfJVrNQx4hG7Zh6YerOThFtPlqrD2HV2bB26dnSoLHse@CFja61ckOQ4ALdZ5Ta5HaHMPa9n69v8HwTZucynoxP/S8)
But because I kinda feel bad for *@cairdCoinheringaahing*, here a brute-force approach with a bit more afford (**83 bytes**):
```
n->{long r=n,a=0,u,k;for(;++a<10;r=u>n?r:a)for(k=2,u=a;u<n;)u=u*10+k++*a;return r;}
```
[Try it online.](https://tio.run/##dZFLboMwFEXnWYXFCMcE2fypQ7qBNJMOqw5c4qQEYpCxI1VRpl1Al9iNUHColBTVA3/Ou/K9eu/ATmxx2JZdXrG2BU@sEOcZAIVQXO5YzsFmeAJQ1WIPctscAtKeXWb91iqmihxsgAAZ6MRidTYKmQmHZdjRTkl3tbQpQmxJMJWZXolH@cDgQMvMc3TGqF4KCnWm5wSjEqE5o5IrLQWQ9NLRwabRb1VvM7qd6mILjn1S@1nJQuxfXgGD15iKt8r2Y@yHJuMIIhJ7iZ@GOCJRuL6t3Mm8IEqJHybYC4I7VZrEURj4xPvn09jDd3oyLBxMEMH@lBHsTUMEf@3xLUiigKRx6GNzibz1ZCCmRUZr5lGIRquxRc8freJHt9bKbfruqUrYpowsYLmSN5z1IfDiF1rQrbjYq3cbQmR9f34BCwk3v5bhaHzpfgA)
**Explanation:**
```
n->{                 // Method with long as both parameter and return-type
  long r=n,          //  Result, starting at the input in case it's already a single digit
       a=0,          //  The digit to start the sequence with
       u,            //  The last number of the sequence we're building for digit a
       k;            //  Multiplier which increments each iteration
  for(;++a<10;       //  Loop in the range [1,9] (over each digit):
      r=u>n?         //    After ever iteration: if `u` is larger than the input:
            r        //     Keep the result the same
           :         //    Else:
            a)       //     Change the result to `a`
    for(k=2,         //   Reset `k` to 2
        u=a;         //   Reset `u` to the current digit `a`
        u<n;)        //   Inner loop as long as `u` is smaller than the input
      u=             //    Change `u` to:
        u*10         //     10 times the current `u`
            +k++*a;  //     With `k` multiplied by `a` added
                     //     (after which `k` increases by 1 with `k++`)
  return r;}         //  And after we iterated over each digit, return the result
```
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 108 bytes
```
[S S S N
_Push_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][S S S T    N
_Push_1][T  S S S _Add][S S S T S S T   N
_Push_9][T  S S N
_Multiply][S S S T  N
_Push_1][N
S S N
_Create_Label_LOOP][S S S T S T S N
_Push_10][T S S N
_Multiply][S N
S _Duplicate][S T   S S S T S N
_Copy_0-based_2nd]S N
T   Swap_top_two][T S S T   _Subtract][N
T   T   S N
_If_neg_jump_to_Label_PRINT][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_PRINT][S S S T    S T S N
_Push_10][T S T S _Integer_divide][T    S T S _Integer_divide][T    N
S T _Output_top_as_number]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.  
`[..._some_action]` added as explanation only.
Port of [*@Grimy*'s 05AB1E answer](https://codegolf.stackexchange.com/a/191306/52210), except that I don't have a builtin to get the first digit. ;)
[Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgQsIObk4QQDIA7IUwIATyuYCC3JBGUAIEeQCqwBxgQIQtUA2kANSiqwWCoF2/P9vZmhuZGFsaWoAYhgAAA) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer i = STDIN as integer
i = i + 1
i = i * 9
Integer t = 1
Start LOOP:
  t = t * 10
  If(i - t < 0):
    Call function PRINT
  Go to next iteration of LOOP
function PRINT:
  t = t / 10
  i = i / t    (NOTE: Whitespace only has integer-division)
  Print i as integer to STDOUT
```
[Answer]
# JavaScript (ES6), ~~16~~ 15 bytes
*Thanks to @Grimy for lifting the 32-bit constraint I had with the previous version.*
Using [Grimy's magical incantation](https://codegolf.stackexchange.com/a/191306/58563). Takes input as a string.
```
n=>(n*9+9+n)[0]
```
[Try it online!](https://tio.run/##jdFNDoIwEAXgvadgNyBRpv@dBV7EuCAKRkNaI8br1wgLQgHjrLr4MvNeeq/eVXd@3h6vnfOXOjRlcOUhdVvKKXfZEU/h7F3n23rf@mvapCAMCgXJOFmWFEUiNpHTzHArSKFmuveDU7Gb7ErWHZeamFAWuZQwOh47skYrKRiHyT77I5/hCKt32XdQQpSPFh1DAX85hlE@Wu47u7vYF@f/MetrtWRklMD@oTkMzoQP "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), 53 bytes
Naive brute force approach.
```
n=>(g=(k,x=i=0)=>x>n?g(k+1):x<n?g(k,++i*k+10*x):k)(1)
```
[Try it online!](https://tio.run/##jdDbDoIwDAbge5@Cy008tDvPOHwW4oEgZBgxhrdHxUR0grFXzfKl7b9jek3r7Tk/Xea@2u3bg2u9S0jmSDFrXO6AuqRJ/CYjRYx01ay7dhbH@fT@ANOGrgpKkLbbytdVuV@UVUYOhGvgMuqL0mi5jPjkUynUzHArQaGSLyUD9T4nGlVMKItcGmBC9IoFyhqtpODIPmaZ8bs0g7GN@CgQwV12SCHwfxQC@6meGcONQxnh67/CjEYJtFpy6BrFnkq3Nw "JavaScript (Node.js) – Try It Online")
[Answer]
# [PHP](https://php.net/), 20 bytes
```
<?=(_.++$argn*9)[1];
```
[Try it online!](https://tio.run/##TYy9CgIxEIT7fQo5LNRD2Z/sJuEUO19CRUTEs0mC@vxG9K5wmvmKb6b0pdb1djM7rdp2en7c0iLO93Ts6vXS50lzSE1XxaMoGHkOEhWNTEGBnUUSDcjOQQze1Anxv@YZgb5BNzShjEDI48GwRQjmKHoV/IHxO5fXPadnXe4@ "PHP – Try It Online")
Yet another [Grimy's answer](https://codegolf.stackexchange.com/a/191306/81663) port!
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
RRḌ÷@fⱮ9
```
[Try it online!](https://tio.run/##y0rNyan8/z8o6OGOnsPbHdIebVxn@f//f2MzSwA "Jelly – Try It Online")
A full program that takes an integer and prints the starter digit. Doesn’t use Grimy’s clever method! Terribly inefficient for larger input. The following version handles all of the test cases but is a byte longer:
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
DJRḌ÷@fⱮ9
```
[Try it online!](https://tio.run/##y0rNyan8/9/FK@jhjp7D2x3SHm1cZ/nf@lHDHAVdO4VHDXOtD7dzHW5/1LQm8v//aGNzA2NTHQUzQ3MjC2NLUwMzQzMgF4iMTMwsDY1NLQyMTEx0FCwtzM1MTYwNjVCUmhsZ6CgYgoCBCZRhaGAMYxkaGMGMgZoAVG1hZmJoaW5qbABmmBnFAgA "Jelly – Try It Online")
[Answer]
# [Hy](http://hylang.org/), 44 bytes
```
(defn a[p](print(get(str(*(+(int p)1)9))0)))
```
Uses Grimy's method
[Try it online!](https://tio.run/##XYw7DsIwEER7TuFyF5r92Gv7LIgiEuHTRFZIw@mdYBeJ2GL15kkzr2@tcB8fkxuu5QZlfk8LPMcFPssMZ7jAll1BxoxIiFhhcBpJA542Mo6SNAcytm76F2@ZNSQS75vIKVrwyvJfi0JN8e/I78ykh8Akh@F9s5eTec4xKDUwwboC "Hy – Try It Online")
[Answer]
# [Keg](https://github.com/JonoCode9374/Keg) `-rr`, 4 bytes
```
⑨9*÷
```
[Try it online!](https://tio.run/##y05N////0cQVllqHt///DwA "Keg – Try It Online")
Of course, uses the same approach as the 05AB1E answer. Also uses the new `-rr` (reverse and print raw) flag.
Transpiles to:
```
from KegLib import *
from Stackd import Stack
stack = Stack()
printed = False
increment(stack)
integer(stack, 9)
maths(stack, '*')
item_split(stack)
if not printed:
    reverse(stack)
    raw(stack)
```
[Answer]
# [Wren](https://github.com/munificent/wren), 30 bytes
Just a port of most answers.
```
Fn.new{|i|(i*9+9).toString[0]}
```
[Try it online!](https://tio.run/##Ky9KzftfllikkKhg@98tTy8vtby6JrNGI1PLUttSU68kP7ikKDMvPdogtvZ/cGVxSWquXnlRZkmqRqJecmJOjoaxpuZ/AA "Wren – Try It Online")
[Answer]
# [W](https://github.com/A-ee/w) [`h`](https://codegolf.meta.stackexchange.com/questions/14337/command-line-flags-on-front-ends/14339#14339), 3 [bytes](https://github.com/A-ee/w/wiki/Code-Page)
```
)9*
```
# Explanation
```
)   % Increment by 1
 9* % Multiply by 9
Flag:h % Take the first item of the result
```
```
[Answer]
# [cQuents](https://github.com/stestoltz/cQuents), 10 bytes
```
D9*_+$)[0]
```
[Try it online!](https://tio.run/##Sy4sTc0rKf7/38VSK15bRTPaIPb/f2NzA2NTAA "cQuents – Try It Online")
Just another port of Grimmy's answer.
```
     $     # Index
   _+      # +1
 9*        # *9
D     )[0] # First digit
```
]