[Question]
  [
The digital root (also repeated digital sum) of a positive integer is the (single digit) value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root of **65536** is **7**, because **6 + 5 + 5 + 3 + 6 = 25** and **2 + 5 = 7**.
---
Sorting all digital roots doesn't make much sense, since it would just start with infinitely many **1**s.
Instead, we'll create lists of all the single digits integers along with their digital roots, then all double digit numbers along with their digital roots, then the triple, quadruple and so on.
Now, for each of those lists, we'll sort it so that all the integers with digital roots of **1** appear first, then all integers with digital roots of **2** and so on. The sorting will be stable, so that the list of integers with a certain digital roots should be in ascending order after the sorting.
Finally we'll concatenate these lists into one single sequence. This sequence will start with all single digit numbers, then all double digit numbers (sorted by their digital root), then all triple digit numbers and so on.
---
### Challenge:
Take a **positive** integer **n** as input, and output the **n**'th number in the sequence described above. You may choose if the list is **0**-indexed of **1**-indexed. 
The sequence goes like this:
```
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 19, 28, 37, 46, 55, 64, 73, 82, 91, 11, 20, 29 ... 
72, 81, 90, 99, 100, 109, 118, ... 
981, 990, 999, 1000, 1009, 1018, 1027, ...
```
### Test cases:
The test cases are 1-indexed.
```
   n   f(n)  
   9      9
  10     10
  11     19
  40     13
  41     22
  42     31
  43     40
  44     49
  45     58
 600    105
 601    114
 602    123
 603    132
 604    141
 605    150
4050   1453
4051   1462
4052   1471
4053   1480
4054   1489
4055   1498
```
Easier to copy:
```
n =    9, 10, 11, 40, 41, 42, 43, 44, 45, 600, 601, 602, 603, 604, 605, 4050, 4051, 4052, 4053, 4054, 4055, 
f(n) = 9, 10, 19, 13, 22, 31, 40, 49, 58, 105, 114, 123, 132, 141, 150, 1453, 1462, 1471, 1480, 1489, 1498
```
### Clarifications:
* You may not output all **n** first elements. You shall only output the **n**'th.
* The code must theoretically work for all integers up to **10^9**, but it's OK if it times out on TIO (or other interpreters with time restrictions) for inputs larger than **999**.
* Explanations are encouraged.
It's [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in each language wins! Don't be discouraged by other solutions in the language you want to golf in, even if they are shorter than what you can manage!
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~78~~ ~~60~~ ~~52~~ ~~46~~ 45 bytes
-6 bytes thanks to [G B](https://codegolf.stackexchange.com/users/18535/g-b).  
-1 byte thanks to [Jakob](https://codegolf.stackexchange.com/users/44945/jakob).
```
n=input()
b=10**~-len(`n`)
print~-b+n/b+n%b*9
```
[Try it online!](https://tio.run/##JYxBCoMwEEX3c4ogFNQiTeKkYMGl3XbTA1jtQKUSQ4i0brx6OqGL9@Yv/h@3hddidRyXJ7VZlkXbTtatIS9gaJUsy72ayea97QtwfrJhr4ajPTGHoWwiLwA@r2kmcfcrXUCI4Ld0hKAvjSL9hZRHckF0t2vn/eL/hcHT4x0bUBKUApSAbA1YAyKggbOUjGI0UzPIGG4amZQ2RifVSZhkfg "Python 2 – Try It Online")
Finally reached a closed form, 1-indexed.
---
# [Python 2](https://docs.python.org/2/), 78 bytes
0-indexed.
```
d=10;k=1
exec'\nk+=9\nif k>d+7:k=d;d*=10\nif k>=d:k-=d/10*9-1'*input()
print k
```
[Try it online!](https://tio.run/##LY0xDsIwDEV3n8LqUiiqSFoXSFHYYGVhZIEmiCooraIg4PQlFgzv2bK@/MdPvA@@mrrBWB2yLJuMlmLrtAT7tl1@9m6h1dn3N3Q7s1i3TputKVLmf9OmdaU2SykKVcq86P34jLM5jKH3Ed2UXgK87v3D4ik8bQuIMXx4IHIDcjPw3tkx4v542IcwhF/gGuzFTRtQIAXUCkgASaAKqAYiaJSClRAJmagSdYJSjDjbCJZkVayaRV8 "Python 2 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 80 bytes
```
f=lambda i,k=1:k>i and sorted(range(k//10,k),key=lambda n:n%-9)[i-k]or f(i,k*10)
```
[Try it online!](https://tio.run/##jY/BTsMwEETP9VesVFVNqkS1GwepgfRWJE58AOLgki1dOTjBuIVc@PWwVkDqkcO8w2hntNMP4dS5YpzDQ0BvAl0Q8P1MF9OiC5WYA9XkQkKuP4ckTW9trSS7nydqEexdTZVdTVbv4@FH5wM2iTfuFRO7XiuZ2TSzONSteTs0Blz1nbvFNn2i3D6Pxz@bMm6u7I7AuAb@0eIW@W9J5@GYcH6lZDpOj6lKzIIfmDOCGq4XsDV9Shks890yi@Fo49cL9gH2j/d77zsfswePxo5bwfuUEloKzdwIXQithS7FjZQsxdqwCpZmlXxZyoiYKTcRRYSOKH8A "Python 3 – Try It Online")
1-indexed. This is the best I could manage in Python 3 (well, except for the [78-byter](https://tio.run/##NYxBDoIwEEXXzCm6MbYGkhZaE0hwp1sPoC5QqzZiIUONcnqcGl28t5j///RjuHW@mC71fmqbx/HcMFcNHQZ75tj4q@UqVXKxaK3nQ0DuhBDp3Y71r@wr/o88JX6WlULsXKYO0@vmWstUBUnAkZw4VjPnA3e@fwYuBJ16/B5SNs9W85Rd4n9I7Ptk@8DW280ascO4PaJt7lMJSoJSoCVocg66AK1BG1hKSSgiJwpCE4aaRkbFjcmjiigdZT4), which is a port of my Python 2 solution below; I think this one is much cooler, though). Python 2 full programs are advantaged for this particular challenge, because `input()` needs a conversion to `int` in Python 3 (+5 bytes), `exec` is a function, rather than a statement (+2 bytes) and `/` performs integer division by default if its arguments are integers in Py 2 (+1 byte), so this is *definitely shorter* than porting [ovs' answer](https://codegolf.stackexchange.com/a/166960/59487).
## How it works
**Setup**
```
f=lambda i,k=1:k>i and ... or f(i,k*10)
```
This defines a recursive function **f** that takes one integer argument **i** and another one, **k**, which defaults to **1**. While **k ≤ i**, the function **f** returns **f(i,10k)**, multiplying **k** by **10** each time until it becomes greater than **i**. 
**Target range and correct indexing**
```
...range(k//10,k)...[i-k]
```
After this set of operation, we're left with **i**, the initial input and the variable **k** which represents the smallest power of **10** greater than **i**. This way, we are able to generate the (integer) range **[floor(k/10), k)**, which basically includes all integers that are:
* greater than or equal to the highest power of **10** less than or equal to **i**
* less than **k**, the smallest power of **10** greater than **i**
Since we disregard the integers smaller than **x = floor(k/10)**, we must shift the indexing so that we account for the missing numbers. The obvious way is to subtract their count, **x**, from **i**, so that we index into the list (after sorting, which is described below), therefore having **i-x**. However, since the list contains **9k/10**, items, and indexing in a list at index **-y** for some positive **y** yields the **yth** element from the end in Python, this is simply equivalent to indexing with **i-k**, hence saving 4 bytes.
**Sorting each *chunk* by the digital root**
```
sorted(...,key=lambda n:n%-9)
```
The formula for the digital root function is **1+((n-1) mod 9)** (see the *Congruence formula* section of [this Wikipedia article](https://en.wikipedia.org/wiki/Digital_root)). As **1** would this way be added to each of them, it is superfluous when sorting, so we're left with **(n-1) mod 9**. The way Python's `%` operator works when given negative numbers on the RHS is very convenient, because we can use **n pymod -9** instead to save yet anther byte.
---
# [Python 2](https://docs.python.org/2/), 72 bytes
Inspired by [Chas Brown's submission](https://codegolf.stackexchange.com/a/166979/59487).
```
lambda i:sorted(range(1,10**len(`i`)),key=lambda n:(len(`n`),n%-9))[i-1]
```
[Try it online!](https://tio.run/##LYtBCsIwFAXX/lNkIyaSQpImgoW6060HUKHVphqsaYkR7enrj7iYWQzvDWO89V5NbXmcuvpxbmriimcfom1oqP3VUsmlWC4762nlKsb43Y7lf@kL@uu@YtzPszVjB5fJ0/S@uc4SWcAshhE9c6Qkzkfq/PCKlDFMQ/gFThbZZsFJS13K9nOxQyTb/W4bQh/S9xxsfZ/WIAVICVqARivQOWgN2sBKCEQiCskRjRhcGpGUPkYl5Uk6yXwB "Python 2 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~73~~ ~~71~~ 70 bytes
```
lambda n:sorted(range(10**len(`n`)),key=lambda i:(len(`~i`),i%9))[n]+1
```
[Try it online!](https://tio.run/##NZDdSsQwEIWv9SnmRkjWETLJZG0L@yS10Mq2GlzTpZaFvfHVY/68@84h5wvJ9b5/rl6H5fQWLtP3@3kC3/2s2z6fxTb5j1mQOhwusxejH6XEr/l@qudcJ3L/60aJ7qmVsvfDM4Vl3cDhDZyHvm8R2gGhJ4VAKhNFyh2nzmSKndaZNIKhTAaB84I5UllYBNskOqostIWTkrhwFJA2hU26QBeOEmIqHDVki1vZJGJrakoqPuqakoxfqaak4@Z/l4VNfYlNSm6bYegeH66b83v8A7ghLMK9kAzhDw "Python 2 – Try It Online")
2 bytes thx to [Mr. XCoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder); and
1 byte thx to [H.PWiz](https://codegolf.stackexchange.com/users/71256/h-pwiz).
This is 0-indexed.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~15 14 10~~ 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
D,Ḣ$‘Ḍḅ9’
```
**[Try it online!](https://tio.run/##AR8A4P9qZWxsef//RCzhuKIk4oCY4biM4biFOeKAmf///zEx "Jelly – Try It Online")**
### How?
Uses a golfed version of the closed-form solution created by [ovs in their Python answer](https://codegolf.stackexchange.com/a/166960/53748)...
The formula exposed by ovs is: **9\*(n%b) + (n/b) + b - 1** where **b=10floor(log(n,10))**
Now if **c** is the count of decimal digits of **n** then **b-1** is **c-1** nines in decimal.  
This is the same as nine times the value of **c-1** ones in decimal (e.g. `111*9=999`).
Furthermore **n/b** is the leading digit of **n** and **n%b** is the rest of the digits as a decimal number.
A formula like **b\*x+y** may be implemented as a conversion of `[x,y]` from base **b**  
(i.e. **b^1\*x + b^0\*y = b\*x+y**)
As such we can take a number, **n** (for example `7045`), split it into the leading and trailing digits, placing the leading digit at the end (`[[0,4,5],7]`), add one to all of the digits of the first item to cater for the addition of **b-1** (`[[1,5,6],7]`) convert these from decimal lists to integers (`[156,7]`), and convert that from base nine (`1411`).
In the implementation below we add one to all of the digits of both items when catering for **b-1** (`[[0,4,5],8]`), convert from decimal lists to integers (`[156,8]`), convert from base nine (`1412`) and then subtract the one this process added (`1411`).
```
D,Ḣ$‘Ḍḅ9’ - Link: positive integer, n    e.g. 4091
D         - to base ten                       [4, 0, 9, 1]
   $      - last two links as a monad:
  Ḣ       -   head (modifies the list too)    4
 ,        -   pair (the modified list) with   [[0, 9, 1], 4]
    ‘     - increment (vectorises)            [[1, 10, 2], 5]
     Ḍ    - from base ten (vectorises)        [202, 5] (since 1*10^2+10*10^1+2*10^0 = 100+100+2 = 202)  
      ḅ9  - convert from base 9               1823 (since 202*9^1 + 5*9^0 = 202*9 + 6*9 = 1818 + 5 = 1823)
        ’ - decrement                         1822
```
---
Previous, 14 byter:
```
æċ⁵DL,’%9ƊƲÞị@
```
**[Try it online!](https://tio.run/##AScA2P9qZWxsef//w6bEi@KBtURMLOKAmSU5xorGssOe4buLQP///zQwNTU "Jelly – Try It Online")**
This one builds the list up to the next power of **10** above the input by sorting these natural numbers by `[digitalRoot, digitCount]` then finds the value at the inputted index.
[Answer]
# [Haskell](https://www.haskell.org/), ~~94~~ 88 bytes
```
([n|x<-[0..],i<-[1..9],n<-[10^x..10^(x+1)-1],until(<10)(sum.map(read.pure).show)n==i]!!)
```
[Try it online!](https://tio.run/##TY7PaoQwEMbvPkUWekjYGDKabBU2p77AHgs2FdlqV6qp6Eo99NlrZwKFHuY3wzf/vluzfLTDsHfMvey8Ct/bOa20Ul72WIBSpZeBKv26KYXk2xFECl6u4d4P/Axa8GUd1dhMfG6bNzWtcyvUcvv8EsG53h8OYh@bPjDHprkPd/bAcJZ1LNSaOce6OiRJqAH7VSkZaAyQzGA2lDOMHMNgWMlOWhOAkBFygiFY2rI6Ml6wWWQeaSKtT@Lf6IGncBToAxI08f8/ZdzKcD//84KaLahvySBegyynMZwBMgr0GQx9A3OK6iPJpoh6QTdNWfhk/7l2Q/O@7Onz0@XyCw "Haskell – Try It Online") 0-indexed.
**Explanation:**
The list comprehension generates the sequence as infinite list in which we index with `!!`:
* `x` is one less than the current number of digits and is drawn from the infinite list `[0,1,2,3, ...]`
* `i` iterates over the range from `1` to `9` and is used for sorting by the digital roots
* `n` iterates over all numbers with `x+1` digits
* `until(<10)(sum.map(read.pure).show)` computes the digital root ([see here for an explanation](https://codegolf.stackexchange.com/a/97760/56433))
* `n` is added to the list if its digital root equals `i`.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 65 bytes
```
.
9
.+
*
L$`
$`
O$`_(_{9})*(_*)
$2
_+
$.&
N$`
$.&
"$+L`^|\d+"^~G`
```
[Try it online!](https://tio.run/##K0otycxLNPz/X4/LkktPm0uLy0clgQuI/FUS4jXiqy1rNbU04rU0uVSMuOK1uVT01Lj8QAqAtJKKtk9CXE1MirZSXJ17wv//JkYA "Retina – Try It Online") 1-indexed. Explanation:
```
.
9
.+
*
L$`
$`
```
Build up a list of lines of `_`s from 0 until the next power of 10 (exclusive).
```
O$`_(_{9})*(_*)
$2
```
Sort them all in order of digital root.
```
_+
$.&
```
Convert from unary to decimal.
```
N$`
$.&
```
Sort them in order of length.
```
"$+L`^|\d+"^~G`
```
Extract the `n`th element.
[Answer]
# [Pyth](https://pyth.readthedocs.io), ~~36 31 25 24 23~~ 22 bytes
1-indexed.
```
@o%tN9rFK^LThBlt`Q-QhK
```
[Test suite!](https://pyth.herokuapp.com/?code=%40o%25tN9rFK%5ELThBlt%60Q-QhK&test_suite=1&test_suite_input=9%0A10%0A11%0A40%0A41%0A42%0A43%0A44%0A45%0A600%0A601%0A602%0A603%0A604%0A605%0A4050%0A4051%0A4052%0A4053%0A4054%0A4055&debug=0)
### How it works (outdated)
```
@smo%tN9dcU^TKhs.lQT^LTSK – Full program. Q = input.
             Khs.lQT      – Take floor(log10(Q))+1 and store it in K.
          U^T             – Generate [0 ... T^K).
         c                – Cut at locations...
                    ^LTSK – Of the powers of 10 less than K.
  m     d                 – Map over those.
   o  N                   – Sort them by...
    %t 9                  – Themselves decremented, modulo 9.
@s                        – Flatten the result and retrieve the Q'th entry.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~19~~ 11 bytes
Port of [my Python answer](https://codegolf.stackexchange.com/a/166960/71256).
-6 bytes(!) thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen).
```
g<°©‰`9*®O<
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/3ebQhkMrHzVsSLDUOrTO3@b/fxMDU1MA "05AB1E – Try It Online")
```
Code           Explanation            Stack
               implicit input         [n]
g              length                 [len(n)]
 <             decrement              [len(n)-1]
  °            10 ** a                [10**(len(n) - 1)]
   ©           store value            [10**(len(n) - 1)]
    ‰          divmod                 [[n // 10**(len(n) - 1), n % 10**(len(n) - 1)]]
     `         push items to stack    [n // 10**(len(n) - 1), n % 10**(len(n) - 1)]
      9*       multiply by 9          [n // 10**(len(n) - 1), n % 10**(len(n) - 1) * 9]
        ®      retrieve value         [n // 10**(len(n) - 1), n % 10**(len(n) - 1) * 9, 10**(len(n) - 1)]
         O     sum the stack          [n // 10**(len(n) - 1) + n % 10**(len(n) - 1) * 9 + 10**(len(n) - 1)]
          <    decrement              [n // 10**(len(n) - 1) + n % 10**(len(n) - 1) * 9 + 10**(len(n) - 1) - 1]
               implicit output
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 23 bytes
```
@o%tN9rF_mJ^TsdtBl`Q-QJ
```
[Try it here.](http://pyth.herokuapp.com/?code=%40o%25tN9rF_mJ%5ETsdtBl%60Q-QJ&input=10&debug=0)
-3 thanks to [Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder)
1-indexed.
[Answer]
# [Perl 6](https://perl6.org), ~~68~~ 58 bytes
```
{({|(10**$++..^10**++$).sort({({.comb.sum}…*==*).tail})}…*)[$_]}
```
[Test it](https://tio.run/##Tc5LTsMwEAbgvU8xqgLk0Vp24oRGVRCHYIcAldSVIiVNFKc8VCJxGjYcgV2PwkWCZ1yJZvVlHv@4032dTXuj4SXj5Yqx5h0uy3ajoZgO/uHDlyIMvSji/BEVRV7ATdsPvm3ysm2eudk34@/nV1gUYcCHdVWPAf0H997TwzjZvNtBmwEKiI7fdbXT5vjDX9t@Y@w1PHxnuyvW1esdRDRq69u2P60tbsAHr9p1@2EOnn7rdDnoDQRwYACVAXyr7/qwABmcDc1h5hp82wz@1YUyVwHAf/@sPGPjZFs50JfbaCmIUqClM9bVqZ6gXT2O0TE5keiErHBXKWfaTcnpkkEmhItP0ZQjpUJTjowTdOJOxWjKkUqiKUemgimRCiqnCVqSsxgdk68lOiEvaV455@iUnC//AA "Perl 6 – Try It Online") 0-based
```
{sort({.chars,({.comb.sum}…*==*).tail},^10**.chars)[$_]}
```
[Test it](https://tio.run/##Tc5fToNAEAbw9z3FpKkWKJJddhdLGoyH8M2oQbqNJFAIS/2ThsTT@OIRfOtRvAgys00sT798M/sNremqZNxbA69JVKwZqz/gsmg2BrLxYJuu9w5R8ZJ3NkQ09XNk9/Xw@/kVZFngR31eVkP4KHgQuDX/fv70MIxTy21vbA8ZLI/fVbkz9vgTvTXdxk438NzdNF2ztsp3sKTVKd823enZ1Q14MC937b4PYW7eW1P0ZgM@HBhAaQH/0HNz/2whhJkLo23de4sLZRc@wP/8LJ6xYZxGKdCXTrWCEwVHC2fM1SmXaJfHMTomS4GWZIVvlXKmt5qsVwwSzl29RlOPEApNPSKWaOlOxWjqEUqgqUdozhTXnGIt0YKcxOiYfC3QkryifeWcojU5Xf0B "Perl 6 – Try It Online") 1-based
## Expanded:
```
{  # bare block lambda with implicit parameter $_
  sort(
    {
      .chars,         # sort by the length first
      (  # generate sequence to find digital sum
        { .comb.sum } # one round of digital sum
        … * == *      # stop when the digital sum matches itself (1..9)
      ).tail          # get the last value
    },
    ^                 # Range up to (and excluding)
      10 ** .chars    # the next power of 10
  )[ $_ ] # index into the sequence
}
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~43~~ 38 bytes
```
->x{9*(x%b=10**~-x.to_s.size)+x/b+b-1}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf166i2lJLo0I1ydbQQEurTrdCryQ/vlivOLMqVVO7Qj9JO0nXsPa/hqGenqGBgYGmXm5iQXVNRQ1XgUJ0hU5adEWsToUuiIrlqv0PAA "Ruby – Try It Online")
Originally a port of the excellent Python answer by ovs, then simplified some more.
[Answer]
# Java 8, 68 bytes
```
n->{int b=(int)Math.pow(10,(n+"").length()-1);return~-b+n/b+n%b*9;}
```
Boring port of [*@ovs*' Python 2 answer](https://codegolf.stackexchange.com/a/166960/52210), so make sure to upvote him!  
-1 byte thanks to *@Jakob*
[Try it online.](https://tio.run/##LZDLbsJADEX3fIUVqVKmeTRPJIjoH8CGJWUxCQMMDU6UTEBVlP56ak9Z3GON5bm@8k0@ZHA7fc9VLfsetlLjuADQaFR3lpWCHT9tAyqXiaKgzrQg9EYaXcEOEDYwY/A58kC54TmxleYats3TjSPfRc9xRFgrvJirK4JYFJ0yQ4e/QenhB@mtfF8V01ywbTuUNdm@3B@NPsGdcrl702m8HI4gxX@oc9PZSBrWgOrJIQ/HceUDrYQ49iGjmnFNSCkpI@U@LKOIETMSRsrIGDn/yiNL65AnlqllZplPwu4H2P/0Rt3DZjBhS@FMja72nPWXcTwM6V7idaxp/gM)
[Answer]
# [K4](http://kx.com/download/), 38 bytes
**Solution:**
```
-1+9/:10/:'(0;c-1)_1_(1+c:#x)#x:1+10\:
```
**Examples:**
```
q)k)-1+9/:10/:'(0;c-1)_1_(1+c:#x)#x:1+10\:40
13
q)k)-1+9/:10/:'(0;c-1)_1_(1+c:#x)#x:1+10\:601
114
q)k)-1+9/:10/:'(0;c-1)_1_(1+c:#x)#x:1+10\:4051
1462
```
**Explanation:**
Port of Jonathan Allan's solution as I run out of memory building the digital roots from 1 to 1e9.
```
-1+9/:10/:'(0;c-1)_1_(1+c:#x)#x:1+10\: / the solution
                                  10\: / convert to base 10
                                1+     / add 1
                              x:       / save as x
                             #         / take from x
                     (      )          / do together
                          #x           / count x
                        c:             / save as c
                      1+               / add 1
                   1_                  / drop the first
                  _                    / cut at these indices
           ( ;   )                     / 2-item list
              c-1                      / length - 1
            0                          / .. zero
      10/:'                            / convert each from base 10
   9/:                                 / convert from base 9
-1+                                    / subtract 1
               
```
**Bonus:**
Translation of ovs' solution is simpler but longer:
```
-1+b+/1 9*(_%;.q.mod).\:x,b:10 xexp#1_$x:
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 19 bytes
```
æḟ©ræċɗ⁵Ṗ%Þ-9⁸‘_®¤ị
```
[Try it online!](https://tio.run/##ATUAyv9qZWxsef//w6bhuJ/CqXLDpsSLyZfigbXhuZYlw54tOeKBuOKAmF/CrsKk4buL////NDA1NQ "Jelly – Try It Online")
-1 thanks to [Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder).
1-indexed.
[Answer]
# J, 24 bytes
```
(]/:([:+/[:".&>":)^:_"0)
```
This *tacit* expression is wrapped in parens to signify that it should be treated on its own rather than as part of any following expression (like the arguments).
The phrase ']/:' orders (ascending '/:') the original array ']' by the sum '+/' of the digits The expression 
```
". &> ":
```
 converts a number to a character vector with '":', then applies its inverse '".' - character to number - applied to each '&>' item. So, 65536 -> '65536' -> 6 5 5 3 6.
The power conjunction '^:' near the end of the expression applies the code we just explained (on the left) a specified number of times. In this case, the specified number of times is infinity '\_' which means to keep applying until the result stops changing.
The final '"0' means to apply the whole expression on the left to each scalar (0-dimensional) item on the right, which would be the array of numbers to which we want to apply this.
[Answer]
# [Elixir](https://elixir-lang.org/), 239 bytes
```
q=:math
e=Enum
r=fn x,f->cond do
x<10->x
1->f.(e.sum(Integer.digits x),f)end end
fn p->e.at(e.at(Stream.unfold({0,[0]},fn {a,c}->{c,{a+1,c++e.sort(trunc(q.pow 10,a)..trunc(q.pow 10,a+1)-1,&r.(&1,r)<=r.(&2,r))}}end),1+trunc q.log10 p),p)end
```
[Try it online!](https://tio.run/##XU6xbsQgFNvzFUwnUB5PoepUXdhuuKlDx6oDIpBGSoAQUJHSfHvK3djBlmXZls08lSme59q/LSp9N6a/ubw0sbeOFLBcau8GMvimXEXHZWkElxapwS0v9O6SGU3EYRqntJHCwDJT4xVN7QcuDapEn/SRolELZmf9PNC9g8/u64Ca2hXog8tdw65aAbpt67iPiaaYnaYrBv9DRAeKIf63WsG4gEtEehEQ2bV/qJeq2HHUEwxE@6yQFWc/io4EBuFx8UT6Khj5leT@jiGn7fwD "Elixir – Try It Online")
Explanation incoming (slowly)! I don't think it can get much shorter than this, but I'm always open to suggestions
[Answer]
# [Perl 5](https://www.perl.org/) `-pF`, 27 bytes
```
$_=9x$#F+$_%10**$#F*9+$F[0]
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3tayQkXZTVslXtXQQEsLyNSy1FZxizaI/f/fxMDU5F9@QUlmfl7xf11fUz0DQ4P/ugVuAA "Perl 5 – Try It Online")
Uses @ovs's formula and @JonathanAllen's explanations to come up with a nice compact piece of code.
]