[Question]
  [
Given an integer `n`, find the next number that follows the following requirements:
* The next greater number is a number where each digit, from left to right, is greater than or equal to the previous one. For example, `1455`:
`1<4`
`4<5`
`5<=5`
* The next greater number has to be bigger than `n`
# Testcases
```
10 -> 11
19 -> 22
99 -> 111
321 -> 333
1455 -> 1456
11123159995399999 -> 11123333333333333
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code wins!
These numbers make up **[A009994](https://oeis.org/A009994)** - Numbers with digits in nondecreasing order.
  
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 3 bytes
```
<.o
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/30Yv//9/S8v/UQA "Brachylog – Try It Online") or [Try more cases](https://tio.run/##SypKTM6ozMlPN/pf/ahtw6Ompoe7Omsfbp3w30Yv////aEMDHQVDSx0FSyA2NjIEckxMTWMB "Brachylog – Try It Online")
```
?<.o.   # implicit input (?) and output (.)
?<.     # the input is smaller than the output
  .o.   # the output is itself when ordered
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 6 bytes
```
ḟoΛ≤d→
```
[Try it online!](https://tio.run/##yygtzv7//@GO@fnnZj/qXJLyqG3S////DS0B "Husk – Try It Online")
### Explanation
```
ḟoΛ≤d→
ḟ       find the first integer
     →  starting from input incremented
 o      such that composed function
  Λ d   every digit
   ≤    is less that or equal to the previous
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
‘DṢƑ$1#
```
[Try it online!](https://tio.run/##y0rNyan8//9RwwyXhzsXHZuoYqj8//9/QxNTUwA "Jelly – Try It Online")
## How it works
```
‘DṢƑ$1# - Main link. Takes n on the left
‘       - Yield n+1
    $1# - Starting from n+1, find the first integer after such that:
 D      -   The digits are
   Ƒ    -   Invariant under
  Ṣ     -   Sorting
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~[52](https://codegolf.stackexchange.com/revisions/240764/1)~~ 41 bytes
*9 bytes saved by AZTECCO and 2 bytes saved by xnor*
```
g(a:b)|[a]>b=a<$a:b|1>0=a:g b
g.show.(+1)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P10j0SpJsyY6MdYuyRbItLMDMmsM7QyAnHSFJK4023S94oz8cj0NbUPN/7mJmXm2KflcCgoFRZl5JQoqCmkKhkbGKHwjQ3MUvqWFoYkRqgoQQFVjiaoAjW@Bqvg/AA "Haskell – Try It Online")
Solves all the cases nearly instantly.
# Explanation
The first thing to observe is that:
> 
> Find the smallest ascending digit number *greater* than \$n\$.
> 
> 
> 
Is significantly harder than:
> 
> Find the smallest ascending digit number *greater or equal to* than \$n\$.
> 
> 
> 
The former has a lot of edge cases around numbers that are themselves ascending in digits while the latter can be solved fairly easily.
But we can turn the latter to the former by just adding 1 before we run our algorithm. If `g` is the function that solves it then we just have `g.show.(+1)` to solve the actual problem.
So I solve the latter first:
```
g(a:b)|[a]>b=a<$a:b|1>0=a:g b
```
This goes along the list until either we meet a pair of digits that is descending (e.g. `21`) or we reach the end. At that point we replace everything left with the digit we just read and exit.
So for example
```
122334555612990
         ^^
122334555666666
```
---
Here's what the solution looks like without this observation just handling the edge cases naively:
### 92 bytes
```
x!q@(a:b:c)|a>b=a<$q|1>0=(x++[a])!(b:c)
x!"9"=""!x++"1"
x!""="1"
x!y=x++show(1+read y)
f=(""!)
```
[Try it online!](https://tio.run/##ZYtBDoIwEEX3PUU7YdGmG1tNpMQS72FcDAKBiCBgIiTcvbburH81/837Dc73quucW9h45pgV2U1smBcWT8m4qXxn@SLlBa@C8fAjCwMDFoB5DApC9/V7rNazuRneXMmpwpKugtSWe1e4B7a9LQdC6XNq@xdNaE1B6T38Eq2OETGpOujYCok9E0t/JI0n4D4 "Haskell – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 35 bytes
```
->x{x.next![x.chars.sort*'']||redo}
```
[Try it online!](https://tio.run/##TYmxDsIgAER3vuKcUFOJgJgw4I80HWhLo4lpG1oTjPjtSJm84fLunX@17zSYdLqFT2CjC@uuDqy7W7@wZfLrkdImRu/66ZtqQvkZnNMqg4YQG2idTVFScEgpy3tRCrmuZXAuJFdaayX1FhTzH0oa5mx3Rz8hhkgAW6GFQWDL/Hysewp6yHbGUNsGxqAlbuzTDw "Ruby – Try It Online")
*-8 thanks to Dingus!*
[Answer]
# [R](https://www.r-project.org/), ~~65~~ 58 bytes
Or **[R](https://www.r-project.org/)>=4.1, 51 bytes** by replacing the word `function` with a `\`.
*Edit: -7 bytes thanks to [@Dominic van Essen](https://codegolf.stackexchange.com/users/95126/dominic-van-essen).*
```
function(n){while(any(diff((n=n+1)%/%10^(n:0)%%10)<0))0
n}
```
[Try it online!](https://tio.run/##TYvRCsIwDEXf@xWDUUiQYdOsQsT5KYKoxYJkIMoQ8dtry1S8Tzk5915zHHK86@GWRgXF53ROlxPs9QHHFCOADrogtEtLbge6dmjLhRuH6Iy@coRCbdNtGyJTQGbwvoDI11TFnmZk5trsQ/joPqxMWz5EnimISGCp@a09/ye/AQ "R – Try It Online") [Try it on rdrr.io (for larger test-cases)!](https://rdrr.io/snippets/embed/?code=f%3Dfunction(n)%7Bwhile(any(diff((n%3Dn%2B1)%25%2F%2510%5E(n%3A0)%25%2510)%3C0))0%0An%7D%0Af(10)%23%20-%3E%2011%0Af(19)%23%20-%3E%2022%0Af(99)%23%20-%3E%20111%0Af(321)%23%20-%3E%20333%0Af(1455)%23%20-%3E%201456%0A)
Straightforward brute-force:
1. Increment `n`.
2. Split to digits (with leading `0`s that don't matter).
3. Take differences.
4. If any of the differences is `<0`, loop back to 1. Otherwise, stop and output `n`.
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
{›Ds≠|
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJ74oC6RHPiiaB8IiwiIiwiMTM5NSJd)
```
{      # While...
 ›     # Increment
  D    # Make three copies
   s≠  # Check if sorted
     | # Do nothing
```
[Answer]
# [Perl 5](https://www.perl.org/) -p, 26 bytes
```
1while++$_-join'',sort/./g
```
[Try it online!](https://tio.run/##DckxDoAgEATA/t5hQoGoC15xr7EiiiFAgMTfi047xdfIY@C5QvRaT4e5c0hKzS3Xvi7r@d9GEBIhZ0HYmQmAdWARYffm0kNObZgSPw "Perl 5 – Try It Online")
The last test case would take about 194 hours (which is 8 days where I live). So I removed the last five digits from the test case to get the result in 7 sec. For "instant" result, also for the last big test case, this is a 78 byte suggestion: `$_++;s/(@{[join"|",map$_."[0-".($_-1)."]",1..9]}).*/substr($1,0,1)x length$&/e` [...try it online!](https://tio.run/##VcfdCsIgGADQe58iRMI1/76ZFx/d9B5jSIHUhm0yDYLq1TO67NydFNboamW@bQ9Z8@Ozn5Zxpi8qbqfEvKK9kVRx5iU0ig5UgFI4vBu10/l@zmXlDIQR0Dw2McyXcmVbHWoFQwAJIrEdENg7RwCgs@AQ0dm/4M9nSWVc5lxlil8 "Perl 5 – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 48 bytes
```
i;f(n){for(i=++n;n=n%10<n/10%10?++i:n/10;);i=i;}
```
[Try it online!](https://tio.run/##NY3BbsIwDIbveQqrUlGiFi1uWkYI2W57gt22HVCgmyUwVVfEAbFX75JW@OLfnz7bYfkdwjiSayWrW3vuJfmiYMeec9RbfkId@2tR0CZlpxx5cveReIDTjlgquAlIE3FXwvkydE7A9YeOB5B/v2HHrczyPSxfIN9nJSwmbZE8pQRA18fdWfE@KiDzoD45mq2MqppPlpC9vWcfM0pigl8qfuoPw6Vn0E7cR9TpDaJAm0JVCWtnEpHGRzTVFI0xAuummXDdrIRdP2NlVk2diH3UPw "C (gcc) – Try It Online")
[Answer]
# [Julia 1.0](http://julialang.org/), ~~34~~ 31 bytes
```
~x=issorted("$(x+=1)") ? x : ~x
```
[Try it online!](https://tio.run/##PYtBCoMwFET3OcUgXURqS39SCxZiu@0xIqaQIlGSFLLy6tYodFbvv5n/@Q5WU1qWOSkbwuij6Xlx4OmoqCxKPJBwx5yW9@gxWGdgHbzRfebAS4Y1uuqgMGkfzJm/XKwQpsFGnjcVCpxaFOU@nbx1cXBcQ7WY9S6fOgTj43pDKXTMuH6hS34jYtRkEII1zW6ISUEZpZSMrnW96Wt9Y2snJNXNfynklh8 "Julia 1.0 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 49 bytes
```
f=lambda n:-~n*(list(`-n`)<sorted(`~n`))or f(-~n)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TY1BDoIwEEX3PUXDamrAOC011ohn8AaAEWITLA2UEDdexA0b45m8ja244K_-_Hl_5vm2d3dtDZ-m1-DqZPfBOmvK2_lSUrNPHmYFje4dFIkp2KFvO1ddoHj4gbUdrcET7F88jVfdVBT3hOq4zW6lBW1c3JVjro0dHLB1bxvtIKLJkUaMEWo7T4Cn4xp0CPJsgc93p0-Om9BAJARVcJwTotSc-VBwDF4I4YFUyt8ilVs_IXKBUiklhQr6d7hYav7zBQ)
Brute force: increments the given number until it is great. Unsurprisingly, chokes on the larger test case.
#### [Python](https://www.python.org), 77 bytes
```
f=lambda n,t=1:(n:=n+t)*([*str(n)]<=sorted(str(n)))or 10*(g:=f(n//10,0))+g%10
```
[Attempt This Online!](https://ato.pxeger.com/run?1=TU1LbsIwEN37FBZSpXEwxWPjCkeYNZueoKpQEAQsBcdKjKqepZts4E7cpnaTRd_q_ebNzyN8x0vrh-F-i_Vi_XyvbVNdD8eKeh4tluBL6-eRFfBR9LEDzz43tm-7eDrCqBlrO4qigHNpa_DLJQouGJufX1BMo7uvi2tOFEtCHW_ttQrgfOTOh1sE9tqHxkWY0cWWzhgjNHQphdTkNbhs7O1UHfeG5x5FbiMSgiYzKQkxZvSSqSRmrpRKhZXWf8FKvyWFKBVqY4xWJmO6keo_xj-_)
This constructs the result directly. Handles all test cases.
[Answer]
# [Python 3](https://docs.python.org/3/), 84
```
f=lambda n:n+1if all(int(i)<=int(j)for i,j in zip(str(n+1),str(n+1)[1:]))else f(n+1)
```
Fails on the last case due to exceeding the maximum recursion depth.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~59~~ 48 bytes
```
f(n,t){t=++n?t=f(n/10-1),10*t+t%10:0;n=t>n?t:n;}
```
[Try it online!](https://tio.run/##LY1BCsMgEEXX9RQSCGg1RJO6MNb0IG0WxdTioqaks2rI2dMJdDGf/3h8JlTPELYtsiyBL@CFyBfwiLVWleZSqyMIKLXqlMseerRdduv2uqfM@EJSBgrhOviFaCWJtpJYvLbRCCdjMJtWG2taS1ZH4jRTtm@SV44meqaf9H1MkUHg9b@i5uiE4OTwnpEiK0o70qqn5XjLhcR/aZB0H2Hh3JF1@wE "C (gcc) – Try It Online")
```
f(n,t){
  t=++n             // increment input
    ? t=f(n/10-1),  // recurse on prefix
      10*t+t%10     //   and append its last digit
    : 0;            // (base case =0)
  n=t>n?t:n;        // max of above and input
}
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 48 bytes
Very simply iterates through numbers starting from the input until a number equals the sorted string representation of itself, then returns that number.
```
param($n)for(;++$n-ne-join("$n"|% T*y|sort)){}$n
```
[Try it online!](https://tio.run/##TY1dS8MwFIbv@yvCyCRxKZh2E0sJFIYXXinOO5FR6yludElNUlTa/vaaplV3Lg6H9@M5tfoEbd6hqgZcinaoc52fCJa0VJqkqxWWoYTwqA6SLLBcdEv0dPndGaUtpW2P5dAH2IKx29yAERnJCL9inFPmjoRF0XgkiVO8FEecxXHs3fVmw9y69okbvo5YMg6lZ0DUoWUbIDf4IOvGMoThq4bCwhsSCO8nS4NpKuuEC1zOwckwTVGAMWN0zoTw8Y/woeeH3bYxVp3uX49OfcnauxEgJk766Hti7qe3c1X8QdLd9ET8fuuDfvgB "PowerShell – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 67 bytes
```
T`9d`d`.9*$
^0
10
.
$*_¶
+`((_+¶)(?!_*\2)(_*¶)*)_*¶$
$2$1
(_+)¶
$.1
```
[Try it online!](https://tio.run/##FYsxCsMwEAT7/UXgAtIZhFeKiqtS5gMpQ3QBp0iTIuRtfoA/JsvbDAOzv/f/8331c7h5v7stvngyFTxncEaCaNtWTB5Cm7Y1huup6SPH0HSYxgMCyUKMII5UEnsfVxrMUDLBS60gmQurmdVix3Y "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation:
```
T`9d`d`.9*$
```
Increment the input.
```
^0
10
```
Deal with any carry.
```
.
$*_¶
```
Convert each digit to unary.
```
+`((_+¶)(?!_*\2)(_*¶)*)_*¶$
$2$1
```
Propagate the first digit greater than its successor to the end of the number. E.g. `11123159995400000`, `11123315999540000`, `11123331599954000`, ... `1123333333333331`, `1123333333333333`.
```
(_+)¶
$.1
```
Convert the digits back to decimal.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 25 bytes
```
≔Ｉ⊕Ｎθ…θ⌕Ｅθ›ι§θ⊕κ¹×⁻Ｌθⅈ§θⅈ
```
[Try it online!](https://tio.run/##TYwxC4MwEIX3/grHC9ghFYfQSYQWoZYOHbqm8dBQPTWJpf31aSIUvOHxeHz3qU4aNcre@8Ja3RKU0jqoSBkckBw2oU@Luy7DEw0wxtJkZsfdzWhyUH5Vj2U3TjCnyUlTA7Vc@9mgdIHXaVK4ihr8xHVrfbHVxUP@bXc9oIVa02LhgtS6DuaAPCCCG00cwpf3nPNDxnMhRJ6JeH7/7n8 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔Ｉ⊕Ｎθ
```
Input `n`, increment it, and turn it into a string.
```
…θ⌕Ｅθ›ι§θ⊕κ¹
```
Print the prefix up to the first digit that is greater than its subsequent digit. (There is an edge case here when all the digits are equal but the remaining code will just fill with that digit because it has no other choice.)
```
×⁻Ｌθⅈ§θⅈ
```
Fill the rest of the string with that digit.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
È-ìn}fUÄ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=yC3sbn1mVcQ&input=MzIx)
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), 7 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
)∙▒sy=▼
```
Port of [my 05AB1E answer](https://codegolf.stackexchange.com/a/240767/52210).
[Try it online.](https://tio.run/##y00syUjPz0n7/1/zUcfMR9MmFVfaPpq25/9/QwMuQ0suS0suYyNDLkMTU1MuQ0NDI2NDU0tTAA)
**Explanation:**
```
      ▼ # Do-while false with pop:
)       #  Increase the current integer by 1
        #  (which will be the implicit input in the first iteration)
 ∙      #  Triplicate it
  ▒     #  Convert the top copy to a list of digits
   s    #  Sort those digits
    y   #  Join it back together to an integer
     =  #  Check if the sorted integer is still the same as the triplicated integer
        # (after the do-while loop, output the entire stack implicitly as result)
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 8 bytes
```
T$<=Ua_a
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhYrQlRsbEMT4xMhXKjosmhDE2OLWCgPAA)
### Explanation
```
          ; a is command-line argument
T         ; Loop till
    Ua    ;   Increment a, and
 $        ;   Fold on
  <=      ;   Less-than-or-equal
          ; is true:
      _   ;   No-op
       a  ; After the loop, autoprint the modified value of a
```
Folding a number such as `1455` on `<=` is the equivalent of computing `1 <= 4 <= 5 <= 5`, which (thanks to Pip's chaining comparison operators) is equivalent to `(1 <= 4) & (4 <= 5) & (5 <= 5)`.
---
Here's a **19-byte** version that can handle the largest test case:
```
O@Ua{y?ya>b?Yab}MPa
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhab_R1CE6sr7SsT7ZLsIxOTan0DEiEyMAXRhoaGRsaGppaWlqbGliAQC5UCAA)
```
O@Ua{y?ya>b?Yab}MPa
  Ua                 ; Increment a
 @                   ; Get its first digit
O                    ; Output it without a newline
    {          }MPa  ; Map this function to each pair of adjacent digits in a:
     y?              ;   Has y been assigned yet?
       y             ;   If so, use that as the next digit
        a>b?         ;   Otherwise, is the first digit of the pair greater than
                     ;   the second digit of the pair?
            Ya       ;   If so, assign the first digit to y and use that
              b      ;   Otherwise, use the second digit
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 6 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
[>Ð{Q#
```
[Try it online](https://tio.run/##yy9OTMpM/f8/2u7whOpA5f//jY0MAQ) or [verify almost all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeX/aLvDE6oDlf/X6vyPNjTQMbTUsbTUMTYy1DE0MTXVMTQ0NDI2NLU0jQUA) (except for the last one, which is shortened a bit).
**Explanation:**
```
[       # Loop indefinitely:
 >      #  Increase the current value by 1
        #  (which will be the implicit input in the first iteration)
  Ð     #  Triplicate it
   {    #  Sort the digits in the top copy
    Q   #  Pop it and another copy and check if they're still the same
     #  #  If it is: stop the infinite loop
        # (after which the remaining third value is output implicitly as result)
```
---
Here a different approach which also handles the largest test case (**14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)**):
```
>Dü›Å¡ćJs˜¬s∍«
```
[Try it online](https://tio.run/##yy9OTMpM/f/fzuXwnkcNuw63Hlp4pN2r@PScQ2uKH3X0Hlr9/7@hoaGRsaGppaWlqbElCAAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXLfzuXw3seNew63Hpo4ZF2r@LTcw6tKX7U0Xto9X@d/9GGBjqGljqWljrGRoY6hiampjqGhoZGxoamlgiWpaWpsSUIxAIA).
**Explanation:**
```
               #  E.g. input = 11123159995399999 
>              # Increase the (implicit) input-integer by 1
               #  STACK: 11123159995400000
 D             # Duplicate it
               #  STACK: 11123159995400000,11123159995400000
  ü            # For each overlapping pair of digits:
   ›           #  Check if the first is larger than the second
               #   STACK: 11123159995400000,[0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0]
    Å¡         # Split the (implicit) input-integer at the truthy positions
               #   STACK: [[1,1,1,2],[3,1,5,9,9],[9],[5],[4,0,0,0,0,0]]
      ć        # Extract head; pop and push first list and remainder-lists
               # separated to the stack
               #  STACK: [[3,1,5,9,9],[9],[5],[4,0,0,0,0,0]],[1,1,1,2]
       J       # Join this first list together to a single integer
               #  STACK: [[3,1,5,9,9],[9],[5],[4,0,0,0,0,0]],1112
        s      # Swap to get the remainder-list
               #  STACK: 1112,[[3,1,5,9,9],[9],[5],[4,0,0,0,0,0]]
         ˜     # Flatten it
               #  STACK: 1112,[3,1,5,9,9,9,5,4,0,0,0,0,0]
          ¬    # Push its first digit (without popping the list)
               #  STACK: 1112,[3,1,5,9,9,9,5,4,0,0,0,0,0],3
           s   # Swap so the list is at the top
               #  STACK: 1112,3,[3,1,5,9,9,9,5,4,0,0,0,0,0]
            ∍  # Extend this digit to the length of this list
               #  STACK: 1112,3333333333333
             « # Append the two strings together
               #  STACK: 11123333333333333
               # (after which the result is output implicitly)
```
[Answer]
**APL 16~~12 16~~ bytes**
~~New Approch~~
`10⊥⌈/\⍎¨⍕1∘+`
It's just a append scan and then maximum of each cell 
doesnt work in case idetified by @ova
`1∘+⍣{∧/2≤/⍎¨⍕⍺}`
Explanation
`1∘+` adds 1
`{∧/2≤/⍎¨⍕⍺}` checks weather each number is bigger than the one preceding it
`1∘+⍣{∧/2≤/⍎¨⍕⍺}` continously adds 1 untill the previous function returns true i.e. A fixed point function
[Answer]
# [Desmos](https://desmos.com/calculator), ~~159~~ ~~155~~ 149 bytes
The code below supports all integers, with negative integers supported as described in [Jonathan Allan's comment](https://codegolf.stackexchange.com/questions/240743/next-greater-number#comment543290_240743).
```
o->T(o+1-sign(o-c)min(1-sign(L-sort(L))^2)),c->T(c)
i=0
o=0
c=0
s=sign(o)
a=abs(o)
L=smod(floor(a/10^{[floor(log(a+1-ss))...0]}),10)
T(n)=\{i=c:n,i\}
```
[Try It On Desmos!](https://www.desmos.com/calculator/kudyekaxyp?nographpaper)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/zmxjxzptrn?nographpaper)
This uses a variable `c` to cache the input so that changes in the input can be detected (with the function `T(n)`), causing the rest of the program to react accordingly (That is why the program won't break if the input is changed while the ticker is still running).
The byte count can actually be lowered significantly if some liberties (A.K.A. removing the caching variable) can be taken with the I/O method:
### ~~127~~ ~~123~~ 117 bytes, with modified I/O method
```
o->o+1-sign(o-i)min(1-sign(L-sort(L))^2)
i=0
o=0
s=sign(o)
a=abs(o)
L=smod(floor(a/10^{[floor(log(a+1-ss))...0]}),10)
```
[Try It On Desmos!](https://www.desmos.com/calculator/r1mmsvewf8?nographpaper)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/ifq2b6tpfy?nographpaper)
This version removes the caching variable `c` and the function `T(n)` completely, which means that the code cannot detect any changes in the input. This means that extra steps have to be taken in order to enter in or change the input and run the code.
I'm not too sure which I/O method is considered the "accepted" version, so I'm putting both.
Also, it's unclear whether or not we have to support negative integers. If we only have to support non-negative integers or positive integers, the code can be shortened even more (the code below uses the caching variable):
### ~~140~~ 134 bytes, supports all non-negative integers
```
o->T(o+1-sign(o-c)min(1-sign(L-sort(L))^2)),c->T(c)
i=0
o=0
c=0
L=mod(floor(o/10^{[floor(log(a+1-sign(o)))...0]}),10)
T(n)=\{i=c:n,i\}
```
[Try It On Desmos!](https://www.desmos.com/calculator/wjnb18vjnj?nographpaper)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/z6px5jlecv?nographpaper)
### ~~128~~ 122 bytes, supports positive integers
```
o->T(o+1-sign(o-c)min(1-sign(L-sort(L))^2))),c->T(c)
i=1
o=1
c=0
L=mod(floor(o/10^{[floor(logo)...0]}),10)
T(n)=\{i=c:n,i\}
```
[Try It On Desmos!](https://www.desmos.com/calculator/kty7afvsl8?nographpaper)
[Try It On Desmos! - Prettified](https://www.desmos.com/calculator/dgavfbyqsg?nographpaper)
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), 95 bytes
```
(load library
(d F(q((N)(i(e N(from-base 10(merge-sort(to-base 10 N))))N(G N
(d G(q((N)(F(a N 1
```
[Try it online!](https://tio.run/##NcsxDsMgFIPhvafw6AyRStMMXCBs7w5EoRUSlBRYcnpCpcbjL3/Vf47gy94aQ7Ibgl@zzceNGxZ@SRno6SB85RTH1RYHdWd0@e3GknJlTVeFDH1CA/lx8@cLLQSqMdodBr32q9LQGtNDQT3nubN2Ag "tinylisp – Try It Online")
-3 from dlosc
`merge-sort` is shorter than `insertion-sort`. Surprisingly there's no plain sort alias. Since variable assignment is global, i've resorted to using `(+ n 1)` everywhere.
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 49 bytes
```
[ [ 1 + dup present [ <= ] monotonic? ¬ ] loop ]
```
[Try it online!](https://tio.run/##PYw5DsIwFAX7nOL1SBEGUphFlIiGBlFZKazkEyJif@OlQIgbcQouZgIF5WhGc9ZNZJ9Px/1ht4TR8YIreUsDnKdANqLznFxvu58sk@0bbgmBbolsQ@HbxXh3vh/bVVE8IKYQElJiPhMQi6rCMysoCEzQJvcfK6w3qGHYcuRxu8X7NfLA7FBnox3K/AE "Factor – Try It Online")
Add 1. If the string representation of the number isn't sorted, repeat.
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 39 bytes
```
a->until(vecsort(d=digits(a))==d,a++);a
```
[Try it online!](https://tio.run/##FYrLCoAgEAB/ZemkpJA9DhH2I9FhyYqFqEUt6OvNDgMzMIye9M5pA5tQj/cZ6RDPuoTLR@Gso51iECiltU5hWcoBEzIfr0DQI7CnM2Yt/ihg@08Fk6kUmF5Bn2lqk6PtulmmDw "Pari/GP – Try It Online")
[Answer]
# APL+WIN, 48 bytes
Prompts for integer
```
n←⍴v←⍎¨⍕⎕+1⋄10⊥⌽((n-⍴v)⍴¯1↑v),⌽v←(^\0≤1,-2-/v)/v
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlCGIFBIBY5lyPOtrT/ucB2Y96t5SBqb5DKx71TgUq0TZ81N1iaPCoa@mjnr0aGnm6ICWaQOLQesNHbRPLNHWA4iA9GnExBo86lxjq6Brp6pdp6pf9B5rK9T@Ny9CAC0hYAglLEGFsZAjim5iagihDQyNjQ1NLS0tTY0sQwCIGAA "APL (Dyalog Classic) – Try It Online")
The final example throws an error in the final digit in Dyalog Classic on TIO. Dropping the last digit of that example gives the expected result.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 39 bytes
```
f=n=>(p=[...++n+''])+''>p.sort()?f(n):n
```
[Try it online!](https://tio.run/##DcRBCoMwEEDR/VzEGZIOpq0LhdiDiItgTWmxM8GEXj8N/P8@4Rfydr5TuYg@9xp9S/yMyS/MbIyYrlupMSfOehakR0ShSWrxC7jeghstjG3XOwu3a8Pdh8HCCptK1mPnQ19Y@BsSRqL6Bw "JavaScript (Node.js) – Try It Online")
Fixed tsh's answer
[Answer]
# [Ly](https://github.com/LyricLy/Ly), 14 bytes
```
1[p`sSaJlf=!]p
```
[Try it online!](https://tio.run/##y6n8/98wuiChODjRKyfNVjG2AMg3MTUFAA "Ly – Try It Online")
This is a pretty straightforward iterative take on the question. It splits the number into digits, sorts them, collapses back to a number, and compare that to the original. The loop ends when the digits are sorted.
```
1              - push a '1' to start the loop
 [p         ]  - loop until the top of the stack is '0'
   `           - increment the current var (first time reads STDIN)
    s          - save number to backup cell
     S         - split the number into digits
      a        - sort the stack
       J       - recombine the digits into a number
        l      - pull the number from the backup cell
         f     - flip the top two entries of the stack
          =    - compare the original and sorted digits
           !   - negate result of comparison
             p - delete iterator var, leaves the answer on the stack
```
[Answer]
# [Perl 5](https://www.perl.org/) `-p`, 38 bytes
```
$_++;s/./$t||($&<$`%10?$t=$`%10:$&)/ge
```
[Try it online!](https://tio.run/##K0gtyjH9/18lXlvbulhfT1@lpKZGQ0XNRiVB1dDAXqXEFsywUlHT1E9P/f/fxNjQ6F9@QUlmfl7xf11fUz0DQ4P/ugUA "Perl 5 – Try It Online")
It's a little longer than @KjetilS' [answer](https://codegolf.stackexchange.com/a/240761), but it has the advantage of being nearly "instant" for any number. Its runtime is based on the length of the number rather than the value. For really big numbers, `-Mbigint` should be added to the command line flags.
[Answer]
# [Raku](https://raku.org/), 27 bytes
```
{first {[<=] .comb},$_^..*}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Oi2zqLhEoTraxjZWQS85PzepVkclPk5PT6v2f3FipYKSSryCrZ1CdZqCSnytkkJafpGCoYGOgqGljoIlEBsbGQI5Jqam/wE "Perl 6 – Try It Online")
* `$_ ^.. *` is the infinite sequence of numbers starting with, but not including (thanks to the `^`), the input number `$_`.
* `first { ... }, ...` returns the first number in that sequence for which the brace-delimited anonymous function returns a true value.
* `.comb` splits the input number into its individual digits.
* `[<=]` reduces the digits with the `<=` operator. It's equivalent to `digit₁ <= digit₂ <= ... <= digitₙ`.
]