[Question]
  [
### Input:
A positive integer **n** consisting of digits in the range **0-9**.
### Challenge:
If **d** is the highest digit in the integer, assume the base of the number is **d+1**. E.g. if the integer is **1256** then you shall assume it's in **base-7**, if it's **10110** then you shall assume it's **base-2** (binary), and if it's **159** then it's decimal.
Now, do the following until you either, 1: reach a **base-10** integer, *or* 2: reach a single digit integer.
1. Convert the integer from **base-(d+1)** to **base-10**
2. Find the base of this new integer (again, **base-(d+1)** where **d** is the highest digit in the new number)
3. Go to step **1**.
---
### Examples:
Assume the input is **n = 413574**. The highest digit **d=7**, so this is **base-8** (octal). Convert this to decimal and get **137084**. The highest digit **d=8**, so this is **base-9**. Convert this to decimal and get **83911**. The highest digit is **9**, so this is a decimal number and we stop. The output shall be **83911**.
Assume the input is **n = 13552**. The highest digit is **d=5**, so this is **base-6**. Convert this to decimal and get **2156**. The highest digit **d=6**, so this is **base-7**. Convert this to decimal and get **776**. The highest digit is **d=7**, so this is **base-8**. Convert this to decimal and get **510**. The highest digit is **d=5** so this is **base-6**. Convert this to decimal and get **186**. The highest digit is **8**, so this is **base-9**. Convert this to decimal and get **159**. The highest digit is **9**, so this is a decimal number and we stop. The output shall be **159**.
Assume the input is **n=17**. This will give us **15**, then **11**, then **3**, which we will output since it's a single digit.
---
### Test cases:
```
5
5
17
3
999
999
87654321  (base-9 -> 42374116 in decimal -> base-7 -> 90419978 in decimal) 
9041998
41253  (5505 -> 1265 -> 488 -> 404 -> 104 -> 29)
29
```
---
**Notes:**
* Standard rules regarding I/O, loopholes etc. You may take the input as a string
* Explanations are encouraged
* You may use builtin base-conversion commands
	+ Solutions that don't use the language's builtin base-conversion functions (if they exist) are welcome, even if they end up being much longer than the obvious approach using builtin functions.
---
Apparently, this is [OEIS A091047](https://oeis.org/A091047).
  
[Answer]
## Mathematica, 56 bytes
```
#//.x_/;(b=Max[d=IntegerDigits@x]+1)<11:>d~FromDigits~b&
```
[Try it online!](https://tio.run/##y00sychMLv6fZvtfWV9fryJe31ojydY3sSI6xdYzryQ1PbXIJTM9s6TYoSJW21DTxtDQyi6lzq0oPxciXJek9j@gKDOvxEErTUHfQaHaVEfB0FxHwdLSUkfBwtzM1MTYyFBHwcTQyNS49j8A "Mathics – Try It Online") (Using Mathics.)
I thought I'd check out what the sequence looks like:
[![enter image description here](https://i.stack.imgur.com/3lFQz.png)](https://i.stack.imgur.com/3lFQz.png)
And here is a plot of the number of steps it takes to find the result:
[![enter image description here](https://i.stack.imgur.com/NR0lg.png)](https://i.stack.imgur.com/NR0lg.png)
(Click for larger versions. See the revision history for plots only up to **n = 1000**.)
Looks like a very interesting mixture of large scale structure and fine scale chaos. I wonder what's up with the wider gaps around 30,000 and 60,000.
[Answer]
# Java 8, ~~172~~ ~~166~~ ~~163~~ ~~152~~ ~~151~~ ~~140~~ ~~138~~ ~~116~~ ~~114~~ 99 bytes
```
s->{for(Integer b=0;b<10&s.length()>1;s=""+b.valueOf(s,b=s.chars().max().getAsInt()-47));return s;}
```
Takes the input as a `String`.
-64 bytes thanks to *@OlivierGrégoire*. And here I thought my initial 172 wasn't too bad.. ;)
[Try it here.](https://tio.run/##hY8/b4MwEMV3PsWJobLVYoUESpFLpI4dmg4dqw62YwgpGOQzqFXEZ6dOxRqxnO7PT@@9O4tRRF2vzfn4PatGIMKbqM0lAKiN07YUSsPhOgJ8OFubChRZGqTc76fAF3TC1QoOYKCAGaP9pewsefUKlbYgiw2Xz/HmDlmjTeVOhO5jjkUY3ks2imbQ7yXBB1kgUydhkVDWih9fK@1e0KsQGiUZpdxqN1gDyKeZX237QTbednEfu/oIrU@/BPz8AkGX6L/odMu6wbHen1xjiGGKhGlI/5@4TcTZKpLn@SrzlD2myW4br4JJvE13CzUF0/wH)
**Explanation:**
```
s->{                    // Method with String as parameter and return-type
  for(Integer b=0;b<10  //  Loop as long as the largest digit + 1 is not 10
      &s.length()>1;    //  and as long as `s` contains more than 1 digit
    s=""+               //   Replace `s` with the String representation of:
         b.valueOf(s,   //    `s` as a Base-`b` integer
          b=s.chars().max().ge‌tAsInt()-47)
                        //     where `b` is the largest digit in the String + 1
  );                    //  End of loop
  return s;             //  Return result-String
}                       // End of method
```
[Answer]
# Pyth, 9 bytes
```
ui`GhseS`
```
[Test suite](https://pyth.herokuapp.com/?code=ui%60GhseS%60&test_suite=1&test_suite_input=5%0A17%0A999%0A87654321%0A41253&debug=0)
Explanation:
```
ui`GhseS`
ui`GhseS`GQ    Implicit variable introduction
u         Q    Repeatedly apply the following function until the value repeats,
               starting with Q, the input.
        `G     Convert the working value to a string.
      eS       Take its maximum.
     s         Convert to an integer.
    h          Add one.
 i`G           Convert the working value to that base
```
[Answer]
# JavaScript (ES6), 63 57 54 53 bytes
```
f=a=>a>9&(b=Math.max(...a+""))<9?f(parseInt(a,b+1)):a
```
Saved 8 bytes thanks to Shaggy and Dom Hastings
```
f=a=>a>9&(b=Math.max(...a+""))<9?f(parseInt(a,b+1)):a;
console.log(f("413574"))
```
[Answer]
# [Python 3](https://docs.python.org/3/), ~~91 78 76 75~~ 73 bytes
*@Emigna shaved off 5 bytes. @FelipeNardiBatista saved 1 byte. @RomanGräf saved 2 bytes*
```
i=input()
while'9'>max(i)and~-len(i):i=str(int(i,int(max(i))+1))
print(i)
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P9M2M6@gtERDk6s8IzMnVd1S3S43sUIjUzMxL6VONyc1D8i0yrQtLinSyMwr0cjUAZEQFZrahpqaXAVFYHHN//8NzQE "Python 3 – Try It Online")
---
## Explanation
```
i=input()                                  - takes input and assigns it to a variable i
while '9'>max(i)and~-len(i):               - repeatedly checks if the number is still base-9 or lower and has a length greater than 1
    i=str(...)                             - assigns i to the string representation of ...
          int(i,int(max(i))+1)             - converts the current number to the real base 10 and loops back again
print(i)                                   - prints the mutated i
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~10~~ 5 bytes
5 bytes saved thanks to *Magic Octopus Urn*
```
F§Z>ö
```
As this grows slow very quickly for large input, I'm leaving the old much faster version here for testing. The algorithm is the same, only the number of iterations differ.
```
[©Z>öD®Q#§
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/@tDKKLvD21wOrQtUPrT8/38TQ2NTcxMA "05AB1E – Try It Online")
**Explanation**
```
[             # start a loop
 ©            # store a copy of the current value in the register
  Z>          # get the maximum (digit) and increment
    ö         # convert the current value to base-10 from this base
     D        # duplicate
      ®Q#     # break loop if the new value is the same as the stored value
         §    # convert to string (to prevent Z from taking the maximum int on the stack)
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~20~~ 16 bytes
Takes and returns a string
```
((⍕⊢⊥⍨1+⌈/)⍎¨)⍣≡
```
`(`…`)⍣≡` apply the following function until two consecutive terms are identical:
 `⍎¨` execute each character (turns the string into a list of numbers)
 `(`…`)` apply the following tacit function to that:
  `⌈/` find the maximum of the argument
  `1+` add one
  `⊢⊥⍨` evaluate the argument in that base
  `⍕` format (stringify, in preparation for another application of the outer function)
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///38nQ4FHbBA2NR71TH3UtetS19FHvCkPtRz0d@pqPevsOrQCSix91LgQrPLRCQd1UXUHd0BxIWFpaAkkLczNTE2MjQyDTxNDI1FgdAA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~60~~ 56 bytes
```
->n{n=(s=n.to_s).to_i(s.bytes.max-47)while/9/!~s&&n>9;n}
```
[Try it online!](https://tio.run/##KypNqvyfZhvzX9curzrPVqPYNk@vJD@@WBNEZmoU6yVVlqQW6@UmVuiamGuWZ2TmpOpb6ivWFaup5dlZWufV/i9QSItOTy0pBmuI/W9iaGxqbgIA "Ruby – Try It Online")
[Answer]
# Mathematica, 52 bytes
```
FromDigits[s=IntegerDigits@#,Max@s+1]&~FixedPoint~#&
```
Pure function taking a nonnegative integer as input and returning a nonnegative integer. Uses the same core mechanic `FromDigits[s=IntegerDigits@#,Max@s+1]` as [Jenny\_mathy's answer](https://codegolf.stackexchange.com/a/128800/56178), but exploits `FixedPoint` to do the iteration. 
[Answer]
# [Perl 6](https://perl6.org), 49 bytes
```
{($_,{.Str.parse-base(1+.comb.max)}...*==*).tail}
```
[Test it](https://tio.run/##TU/LboMwELzvV@wham0gDgYMWIi0/9De2qoi4FZIvAROlSpKfqy3/hjFpqp68M5qdmZ2PaixiefjpPAjZmUG7SfelH2lMJ/PZPPqndmDHtlQjJPaHopJEe6ysm8PrC1O9MIYc/LcoUwXdXOZF/O9VpPGHJu6UxOh7H1UA7lz6PeXtZHdc@Xu6JOT@S9s7HU/koBmYPY/LsYMhqbo0LUpGbz142/gdo9kU3fDUXsbdRpUqVVF8QyI9YTmXuKuY@qh@6fwcCXxireY75dyxb8hXGYBAoAnEAJIKe2DNIlFFAYckZj/bqXZHQVhEnEeY91hpcq6LRpDW0FiOulHXMok/SegCCubAkQ8EOGSKIQvjJwHscUoTS34kWVXCCSFQP4A "Perl 6 – Try It Online")
## Expanded:
```
{
  (
    $_,                 # seed the sequence with the input
    {
      .Str
      .parse-base(      # parse in base:
        1 + .comb.max   # largest digit + 1
      )
    }
    ...                 # keep generating values until
    * == *              # two of them match (should only be in base 10)
  ).tail                # get the last value from the sequence
}
```
[Answer]
# [PHP](https://php.net/), 71 bytes
```
for(;$b<10&9<$n=&$argn;)$n=intval("$n",$b=max(str_split($n))+1);echo$n;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRoMClkliUnmerZGJoZGqsZM31Py2/SMNaJcnG0EDN0kYlz1YNrMBaE8jMzCspS8zRUFLJU9JRSbLNTazQKC4pii8uyMks0VDJ09TUNtS0Tk3OyFfJs/7/HwA "PHP – Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 17 bytes
```
Wa>9>YMXaaFB:1+ya
```
Takes input as a command-line argument. [Try it online!](https://tio.run/##K8gs@P8/PNHO0i7SNyIx0c3JylC7MvH///8mhkamxgA "Pip – Try It Online")
### Explanation
This was fun--I got to pull out the chaining comparison operators.
We want to loop until the number is a single digit OR contains a 9. Equivalently, we want to loop while the number is multiple digits AND does not contain a 9. Equivalently, loop while the number is greater than 9 AND the maximum digit is less than 9: `a>9>MXa`.
```
Wa>9>YMXaaFB:1+ya
                   a is 1st cmdline arg (implicit)
     YMXa          Yank a's maximum digit into the y variable
Wa>9>              While a is greater than 9 and 9 is greater than a's max digit:
         aFB:1+y    Convert a from base 1+y to decimal and assign back to a
                a  At the end of the program, print a
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~60~~ ~~59~~ ~~56~~ 53 bytes
Saved 4 byte thanks to *Felipe Nardi Batista*  
Saved 3 bytes thanks to *ovs*
```
f=lambda x,y=0:x*(x==y)or f(`int(x,int(max(x))+1)`,x)
```
[Try it online!](https://tio.run/##Rcs7CsMwDIDhvacw8WK1HuJXEwV8lzgU00LzIGSQT@/WEGINAv0f2tLxXhedc/TfME@vwEgm3w50F@R9gnVnUYyf5RAky54DCQJ4KBglQd72EqNoXAPAzuHudnXVVeCmdkS8gP@PKn33dNZoVZhjaxViX9Uq7cz5yTXmHw "Python 2 – Try It Online")
Using a recursive lambda, comparing the result of the base conversion to the previous iteration.
[Answer]
## C#, 257 244 243 244 233 222 bytes
```
using System.Linq;z=m=>{int b=int.Parse(m.OrderBy(s=>int.Parse(s+"")).Last()+""),n=0,p=0;if(b<9&m.Length>1){for(int i=m.Length-1;i>=0;i--)n+=int.Parse(m[i]+"")*(int)System.Math.Pow(b+1,p++);return z(n+"");}else return m;};
```
Well, C# always takes a lot of bytes but this is just ridiculous. None of the built-ins can handle an arbitrary base, so I had to calculate the conversion myself. Ungolfed:
```
using System.Linq;
z = m => {
int b = int.Parse(m.OrderBy(s => int.Parse(s + "")).Last()+""), n = 0, p = 0; //Get the max digit in the string
if (b < 9 & m.Length > 1) //if conditions not satisfied, process and recurse
{
    for (int i = m.Length - 1; i >= 0; i--)
        n += int.Parse(m[i] + "") * (int)System.Math.Pow(b+1, p++); //convert each base-b+1 representation to base-10
    return z(n + ""); //recurse
}
else return m; };
```
[Answer]
# Mathematica, 92 bytes
```
f[x_]:=FromDigits[s=IntegerDigits@x,d=Max@s+1];(z=f@#;While[d!=10&&Length@s>1,h=f@z;z=h];z)&
```
[Answer]
# Javascript (ES6) with 0 arrow function, 74 bytes
```
function f(a){a>9&&b=Math.max(...a)<9&&f(parseInt(a,b+1));alert(a)}f('11')
```
[Answer]
# [K4](http://kx.com/download/), 19 bytes
**Solution:**
```
{(1+|/x)/:x:10\:x}/
```
**Examples:**
```
q)\
  {(1+|/x)/:x:10\:x}/413574
83911
  {(1+|/x)/:x:10\:x}/13552
159
  {(1+|/x)/:x:10\:x}/17
3
  {(1+|/x)/:x:10\:x}/41253
29    
```
**Explanation:**
Use `/:` built-in to convert base.
```
{(1+|/x)/:x:10\:x}/ / the solution
{                }/ / converge lambda, repeat until same result returned
            10\:x   / convert input x to base 10 (.:'$x would do the same)
          x:        / store in variable x
 (     )/:          / convert to base given by the result of the brackets
    |/x             / max (|) over (/) input, ie return largest
  1+                / add 1 to this
```
[Answer]
# [Kotlin](https://kotlinlang.org), 97 bytes
```
fun String.f():String=if(length==1||contains("9"))this else "${toInt(map{it-'0'}.max()!!+1)}".f()
```
## Beautified
```
fun String.f(): String = if (length == 1 || contains("9")) this else "${toInt(map { it - '0' }.max()!! + 1)}".f()
```
## Test
```
fun String.f():String=if(length==1||contains("9"))this else "${toInt(map{it-'0'}.max()!!+1)}".f()
val tests = listOf(
        5 to 5,
        17 to 3,
        999 to 999,
        87654321 to 9041998,
        41253 to 29
)
fun main(args: Array<String>) {
    tests.forEach { (input, output) ->
        val answer = input.toString().f()
        if (answer != output.toString()) {
            throw AssertionError()
        }
    }
}
```
## TIO
[TryItOnline](https://tio.run/##TU9BbsIwELznFUtUCVuFCBNSMGqQOHDoqYe+wEI2sRpsZC+lVcjb0zgBwh689szseOfbYqlN06izgS902hwSRei6v+ZakVKaAxZ5zq7XvTUotPEk5jGlWGgPsvQS4pcK7YdBchSnSuN0PBvXyVH8EjoavTJax8Gy+REloPToIYdSe/xUJIJbZYAWssnjzZYBSAeAcx6Qtg3YavmWLdI564jZgnG+GsgFm2dpYOY8olEU4h3b3YlwB7+GrXPi770PuaFQdWPdcomybif2BVRAtDmdcQL2jG2nMN083EMWYfxFujZMJ0vQ9naEhrQPpVZAbspRfrN60t7/vhcWzl5g6710qK3ZOWfdk1sd9Wfd/AM)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 8 bytes
```
ωoṠBo→▲d
```
[Try it online!](https://tio.run/##ATUAyv9odXNr/23igoH/z4lv4bmgQm/ihpLilrJk////WzUsMTcsOTk5LDg3NjU0MzIxLDQxMjUzXQ "Husk – Try It Online")
```
ωoṠBo→▲d
ω           # repeat until output no longer changes:
 oṠ         # apply function to value & function-of-value
       d    # value: digits of argument
   Bo→▲     # function of value:
   B        # interpret digits as base n, with n given by
    o→▲     # max digit +1
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 25 bytes
```
>9©(A=Uì rw)<9?ßUs nAÄ):U
```
[Try it online!](https://tio.run/##y0osKPn/387y0EoNR9vQw2sUiso1bSztD88PLVbIczzcomkV@v@/oTkA "Japt – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
DḅṀ‘$$µÐL
```
[Try it online!](https://tio.run/##ASAA3/9qZWxsef//ROG4heG5gOKAmCQkwrXDkEz///80MTI1Mw "Jelly – Try It Online")
[Answer]
# C, ~~159~~ 157 bytes
```
#include <stdlib.h>
char b[99];i=0;m=-1;c(n){do{m=-1;sprintf(b,"%d",n);i=0;while(b[i]){m=max(b[i]-48,m);i++;}n=strtol(b,0,++m);}while(b[1]&&m<10);return n;}
```
[Answer]
# [Scala](http://www.scala-lang.org/), 119 bytes
```
if(x.max==57|x.length==1)x else{val l=x.length-1
f((0 to l).map(k=>(((x(k)-48)*math.pow(x.max-47,l-k))) toInt).sum+"")}
```
[Try it online!](https://tio.run/##VY7NTsMwEITvfoqVT16KI9wmuEFyJY4cOPEEpnXaEMexGhcshTx7MD8Nymln55tZbb/XVk/d65vZB3jWtQMTg3GHHh69Hwg5mAoqFh9ewrl2R/ybapjq5GatjkoV8jNm1rhjOCklMIKxvRnetQWrroALUjF2B6EDi6nmWaN2jLHIGuT5Fm9aHU6Z7z5@j/Jc3lreIGJqPLmAWX9pV5TiOI2E@PRCsI7RAvgO6KpKiiL@@0LOQMgFKctyRkkv2FbeF/lmLebA1VikcrEuNnPkZ/vmZJy@AA "Scala – Try It Online")
# [Scala](http://www.scala-lang.org/), 119 bytes
```
if(x.max==57|x.length==1)x else f((0 to x.length-1).map(k=>(((x(k)-48)*math.pow(x.max-47,x.length-1-k))) toInt).sum+"")
```
[Try it online!](https://tio.run/##VY7BbsIwEETv/oqVT17AUQ0JJpWMxLGHnvoFLjghTeJYxKiWgG9PTVuCctrZebOj7fe60UP3@WX2Ht51ZcEEb@yhh51zF0IOpoCChdcPf6psif9TXYYqukmrg1KZvIakMbb0R6UEBjBNb@IRewHfwQNxgTHuWK22jLHAauTpBmet9sfEdd9/ZTyVi@cBrxExdrxZj0l/bueU4nAjxMUXfGMZzYBvgc6LqCji0xdyBEJOSJ7nI4p6wjZynaWrpRgDD2OSSsUyW42R3@3OyW34AQ "Scala – Try It Online")
Both methods work the same way, but in the first one I put `x.length-1` in a variable, and in the second one I don't.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 12 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
_=ì)ìZrÔÄ}gN
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=Xz3sKexactTEfWdO&input=MTI1Ng)
[Answer]
# [J](http://jsoftware.com/), 22 bytes
```
(#.~1+>./)@(,.&.":)^:_
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/NZT16gy17fT0NR00dPTU9JSsNOOs4v9rcnGlJmfkK6QpGSjEKpgqGJorWFpaKliYm5maGBsZKpgYGpka/wcA "J – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
fG›β)Ẋ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJBIiwiIiwiZkfigLrOsinhuooiLCIiLCI1XG4xN1xuOTk5XG44NzY1NDMyMVxuNDEyNTMiXQ==)
Will be 5 bytes once a [bug fix](https://github.com/Vyxal/Vyxal/pull/1480) is made.
## Explained
```
fG›β)Ẋ
    )Ẋ # Until the result of applying the following does not change:
fG     #   Get the biggest digit of the current value - should just be G, but bugs
  ›β   #   and convert the current value from base (the biggest digit + 1) to base 10
```
]