[Question]
  [
The year 2013 had an interesting property: the digits are consecutive when sorted (0123). Let's call this type of number a *sortable number:* a non-negative integer whose base-10 digits are consecutive after sorting. Unfortunately, this won't happen again until 2031, and after that, not until 2103. Your challenge is to write a program or function that, when given a non-negative integer through any standard method, outputs or returns the next sortable number.
## Rules
* Input and output must be in base 10.
* Output may be in any reasonable format (number literal, string literal, single-item array, ...).
* Your code must produce the proper output within 1 minute for all inputs up to 98764.
## Test cases
```
    0 -> 1
    1 -> 2
    9 -> 10
   10 -> 12
   11 -> 12
   99 -> 102
  233 -> 234
  234 -> 243
  243 -> 312
 2016 -> 2031
 2031 -> 2103
 2103 -> 2130
 2130 -> 2134
 2134 -> 2143
 9876 -> 10234
98764 -> 98765
```
The sortable numbers form [A215014](http://oeis.org/A215014). A list of all entries up to 98765 can be found [here](https://gist.github.com/ETHproductions/4937931975a5397b9035227af57fe2f1).
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so **the shortest code in bytes wins.**
  
[Answer]
# [Python 2](https://docs.python.org/2/), 61 bytes
```
f=lambda n:-~n*(`sorted(`n+1`)`[2::5]in'0123456789')or f(n+1)
```
[Try it online!](https://tio.run/nexus/python2#Jc3bCsIwDIDha32K3Iy2WqHHHQo@iQidzEFhZjLnra8@E735@EkC2cbz1D9uQw@YTh88yPyal/U@yIxHm1W@uJTitaAw1vkQ66bthJoXGCXt1TZSIhQEaTRYDR3JxUntvGcCEbiMrVlPa2cNT6w3P@mka5v6b1Bpv3suBVcQVXwnIARUIFHzY6W2Lw "Python 2 – TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~11~~ ~~10~~ 9 bytes
```
⁵ḶwṢ
‘Ç1#
```
Returns a singleton array. [Try it online!](https://tio.run/nexus/jelly#@/@ocevDHdvKH@5cxPWoYcbhdkPl/9ZKh9sfNa1x///fQEfBUEfBEkiCWCAmkG1kbAwiTICECYhlYGgGIo2B0kaGBiARQ2MDMAlUYmlhbgYhTQA "Jelly – TIO Nexus")
### How it works
```
‘Ç1#  Main link. Argument: n
‘     Increment; yield n+1.
 Ç1#  Apply the helper link to k = n+1, n+2, n+3, ... until one of them maps to a
      truthy value. Yield a singleton array containing that value of k.
⁵ḶwṢ  Helper link. Argument: k
⁵     Set the return value to 10.
 Ḷ    Unlength; yield [0, ..., 9].
   Ṣ  Sort; yield the sorted array of k's decimal digits.
  w   Window-index; yield the 1-based index(truthy) of the digit array in
      [0, ..., 9], 0 (falsy) if not found.
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), 8 bytes
```
`QtVSdqa
```
[Try it online!](https://tio.run/nexus/matl#@58QWBIWnFKY@P@/kYGhGQA) Or [verify all test cases](https://tio.run/nexus/matl#S/ifEFgSFpxSmPg/1iXkvwGXoQKXJZchkDbksrTkMjI2BmITLiMTIG1gaAYkjA25jAwNgFxDYwMQYcJlaWFuBiZMAA).
### Explanation
```
`     % Do...while
  Q   %   Add 1. Takes input (implicit) in the first iteration
  t   %   Duplicate
  V   %   Convert to string. This gives an array of chars (same as a string)
      %   representing the digits
  S   %   Sort
  d   %   Consecutive differences between the chars (automatically converted
      %   to ASCII codes)
  q   %   Subtract 1. This gives an array where consecutive differences equal 
      %   to 1 are converted to 0, and the rest give a nonzero result
  a   %   True if any value is nonzero. This is the loop condition: if true
      %   (which means at least one consecutive difference was not 1), go on
      %   with the next iteration. Else exit loop
      % End do...while (implicit)
      % Display (implicit)
```
[Answer]
## JavaScript (ES6), ~~64~~ 54 bytes
*Saved a massive 10 bytes, thanks to Neil*
```
f=n=>[...++n+''].sort().some((v,i,a)=>v-i-a[0])?f(n):n
```
### Test cases
```
f=n=>[...++n+''].sort().some((v,i,a)=>v-i-a[0])?f(n):n
console.log(f(0));      // -> 1
console.log(f(1));      // -> 2
console.log(f(9));      // -> 10
console.log(f(10));     // -> 12
console.log(f(11));     // -> 12
console.log(f(99));     // -> 102
console.log(f(233));    // -> 234
console.log(f(234));    // -> 243
console.log(f(243));    // -> 312
console.log(f(2016));   // -> 2031
console.log(f(2031));   // -> 2103
console.log(f(2103));   // -> 2130
console.log(f(2130));   // -> 2134
console.log(f(2134));   // -> 2143
console.log(f(9876));   // -> 10234
console.log(f(98764));  // -> 98765
```
[Answer]
# Pyth - ~~11~~ 10 bytes
```
f}S`TjkU;h
```
[Test Suite](http://pyth.herokuapp.com/?code=f%7DS%60TjkU%3Bh&test_suite=1&test_suite_input=2012%0A2013%0A2016%0A9876%0A98764&debug=0)
[Answer]
## PowerShell v2+, ~~71~~ ~~68~~ 67 bytes
```
param($n)do{$n++}until(-join(0..9)-match-join([char[]]"$n"|sort))$n
```
[Try it online!](https://tio.run/nexus/powershell#@1@QWJSYq6GSp5mSX62Sp61dW5pXkpmjoZuVn5mnYaCnZ6mpm5tYkpwBEYhOzkgsio6NVVLJU6opzi8q0dRUyfv//7@hpYUhAA "PowerShell – TIO Nexus")
An iterative solution that runs pretty much instantaneously on my machine.
```
PS C:\Tools\Scripts\golfing> measure-command {.\find-the-sortable-years.ps1 98764} | fl totalseconds
TotalSeconds : 0.0487127
```
Yes, that's a `do`/`until` loop in a code-golf. Sorry, not sorry. Basically we loop upwards from our input `$n` until `$n|sort`ed regex `-match`es against `0123456789`. Then we place `$n` on the pipeline, and output is implicit.
Saved a byte by realizing that `-join(0..9)` is one byte shorter than the literal string `0123456789`.
[Answer]
## Mathematica, 63 bytes
```
#+1//.x_/;!Differences@Sort@IntegerDigits@x~MatchQ~{1...}:>x+1&
```
Replaces `#+1` with the next value as long as `Differences@Sort@IntegerDigits@x~MatchQ~{1...}` is false, which is the condition that the current value is sortable.
Here's another fun idea, that unfortunately ended up being way too long:
```
FirstCase[FromDigits/@Union@@Permutations/@Join@@Array[Range,{9,10},0],x_/;x>#]&
```
In this one, I'm generating all the sortable years first and then I select the first one that is greater than the input.
Some more ideas that didn't turn out to be shorter than the first attempt:
```
#+1//.x_/;Array[Range,{9,10},0]~FreeQ~Sort@IntegerDigits@x:>x+1&
#+1//.x_/;Subsequences@Range[0,9]~FreeQ~Sort@IntegerDigits@x:>x+1&
#+1//.x_/;0~Range~9~FreeQ~{___,##&@@Sort@IntegerDigits@x,___}:>x+1&
```
[Answer]
# PHP, ~~105~~ ~~103~~ 89 bytes
New 89 bytes version thanks to Titus:
```
for(;!$p;){$t=str_split($n=++$argv[1]);sort($t);$p=strstr('0123456789',join($t));}echo$n;
```
Usage: 
```
php -r "for(;!$p;){$t=str_split($n=++$argv[1]);sort($t);$p=strstr('0123456789',join($t));}echo$n;" 9000
```
Previous 103 bytes version thanks to Xanderhall:
```
<?for($p=0;!$p;){$t=str_split($n=++$_GET[n]);sort($t);$p=strstr('0123456789',implode($t));}echo "$n\n";
```
Previous 105 bytes version:
```
<?for($n=$_GET[n]+1;;$n++){$t=str_split($n);sort($t);if(strstr('0123456789',implode($t))){echo$n;exit;}}
```
Usage: `sortable-years.php?n=9000` outputs `9678`.
Ungolfed version with test cases:
```
$test = array(0,1,9,10,11,99,233,234,243,2016,2031,2103,2130,2134,9876,98764);
foreach ($test as $argv[1]) {
    for(;!$p;){
        $t=str_split($n=++$argv[1]);
        sort($t);
        $p=strstr('0123456789',join($t));
    }
    echo "$n\n"; // add newline for testing
    $p=false; // reset $p for testing
}
Output:
1
2
10
12
12
102
234
243
312
2031
2103
2130
2134
2143
10234
98765
```
[Test online! (New 89 bytes version)](http://sandbox.onlinephpfunctions.com/code/923855caa7033f41df3b2ee35cf84a80df48263b)
[Test online! (Previous 103 bytes version)](http://sandbox.onlinephpfunctions.com/code/f1fff3e3d40de0a1e22bc99100c34e67fe4eded2)
[Test online! (Previous 105 bytes version)](http://sandbox.onlinephpfunctions.com/code/83a6784c6c461ba68f931688e9d6d39f19000147)
Execution time maybe <= 1 second for all the test cases.
[Answer]
# [Perl 6](https://perl6.org), 49 bytes
```
{first {$/eqv($/=.comb.sort).minmax.list},$_^..*}
```
## Explanation
```
{
  first
  {
    $/             # sorted list from later
    eqv            # is it equivalent
    (
      $/           # store in match variable ( doesn't need to be declared )
      =
      .comb.sort   # sorted list of digits from currently tested value
    ).minmax       # the Range of digits
            .list  # flattened to a list
  },
  $_  ^..  *       # Range starting just after input
}
```
## Test:
```
# give it a lexical name for clarity
my &code = {first {$/eqv($/=.comb.sort).minmax.list},$_^..*}
my @all = +«'sortable.txt'.IO.lines;
my @gen = code(-1), &code ... ( * >= 98765 );
say @all eqv @gen; # True
say now - INIT now; # 16.3602371
```
[Answer]
# C#, ~~153~~ ~~130~~ 101 bytes (~~122~~ ~~99~~ 83 excluding namespace declarations)
```
using System.Linq;n=>{while(!"0123456789".Contains(string.Concat((++n+"").OrderBy(x=>x))));return n;}
```
**-23 bytes thanks to pinkfloydx33**
**another -29 thanks to Link Ng (I really should have known I don't need to convert it into an array)**
Damn conversions.
(Added bonus this is surprisingly fast)
[Answer]
# [Befunge](http://github.com/catseye/Befunge-93), 117 bytes
```
&>1+0v
9`#v_>:9+0\4p1+:
1:$<v
0g1+>00p:55+%9+1\4p55+/:!#v_0
v+*g09:<".........." 9p09 <
>:00g-v^<
-9:p09_v|
$v@._<$<>
```
[Try it online!](http://befunge.tryitonline.net/#code=Jj4xKzB2CjlgI3ZfPjo5KzBcNHAxKzoKMTokPHYKMGcxKz4wMHA6NTUrJTkrMVw0cDU1Ky86ISN2XzAKdisqZzA5OjwiLi4uLi4uLi4uLiIgOXAwOSA8Cj46MDBnLXZePAotOTpwMDlfdnwKJHZALl88JDw-&input=MjAxMw)
The way we test if a year is sorted is by creating an "array" (written into the string literal on line five) and for every digit in the year, we set that index into the array to 1. Once all the digits have been processed, we count how many 1s there are in sequence, and if that count equals the year length we can assume the year is sorted.
**Detailed Explanation**
```
&>1+                              Read the year and increment it.
    0v                            The "array" is initialized with zeros prior
9`#v_>:9+0\4p1+:                     to processing each year.
1:$<v                             For every digit, set the corresponding array index
0g1+>00p:55+%9+1\4p55+/:!#v_0       to one, and increment the year length counter.
                      p09 <       Initialise the sequence counter to zero.
                     9            Push a marker onto the stack.
        ".........."              Push the values from the array onto the stack.
v+*g09:<                          Increment the sequence counter for every 1 in the
>:00g-v^<                           array and reset it on every 0. Break if it equals
-9:p09_v|                           the year length or we encounter the end marker.
  @._<$<                          If we have a match, clear the stack and output the year.
$v      >                         If we've reached the marker, drop it try the next year.
```
[Answer]
# Ruby, 51 bytes
```
->n{n+=1 until'0123456789'[n.to_s.chars.sort*''];n}
```
[Answer]
# Python 2, 68 bytes
```
n=input()+1
while''.join(sorted(`n`))not in'0123456789':n+=1
print n
```
Well beaten by @Dennis but just posted as an alternative method anyway.
[Answer]
## C#, 127 bytes
```
using System.Linq;n=>{char[]s;while((s=(++n+"").OrderBy(x=>x).ToArray()).Select((x,i)=>i>0&&x-s[i-1]!=1).Any(x=>x));return n;};
```
~~Beat the current C# submission by 3 bytes :p~~ Beaten back already  
I know this answer will be beaten back easily...  
[repl.it demo](https://repl.it/EqwA/1)
Ungolfed
```
n=>
{
    char[] s;
    while((
        // Store char array in variable to be referenced in Select()
        // Increment n and cast to string
        s=(++n+"")
            // Sort ascending, to array
            .OrderBy(x=>x)
            .ToArray())
        // Convert char to true if it's not at position 0,
        // and it is not 1 greater than the previous char
        .Select((x,i)=>i>0&&x-s[i-1]!=1)
        // All false: n is sortable
        // Any true: n is not sortable
        .Any(x=>x))
    // while loop body is empty
    ;
    return n;
};
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~10~~ 9 bytes
-1 thanks to Emigna.
```
[>D{žhså#
```
[Try it online!](http://05ab1e.tryitonline.net/#code=Wz5Ee8W-aHPDpSM&input=Mg)
New description coming when I have time.
[Answer]
# Python 2, ~~118 117 114~~ 108 Bytes
```
x,s=input()+1,sorted
while[j for i,j in enumerate(s(str(x))[1:])if int(s(str(x))[i])+1!=int(j)]:x+=1
print x
```
EDIT:
-1 Byte thanks to @Gábor Fekete
-6 Bytes thanks to @Zachary T
[Answer]
# PHP, ~~90~~ ~~89~~ 88 bytes
a completely different approach:
```
while(array_unique($a=str_split($n=++$argv[1]))!=$a|max($a)-min($a)-count($a)+1);echo$n;
```
Run with `-r`.
**breakdown**
```
while(
    array_unique(           // 3. unique values
        $a=str_split(       // 2. split to digits
            $n=++$argv[1]   // 1. increase number
        )
    )
    !=$a                    // 4. repeat while unique digits differ from original digits
    |                       // or
        max($a)-min($a)     // digit range
        -count($a)+1        // differs from count-1
    );
echo$n;                 // print result
```
[Answer]
**Clojure, ~~104~~ ~~96~~ 91 bytes**
Long method names don't make this that short... At least `map-indexed` and `-` get main calculations done in a neat way.
*Edit 1*: Neat, I forgot also `=` can take multiple arguments so I don't need to check if count of distinct values is 1.
*Edit 2*: No need to run `(sort(seq(str %)))`, `(sort(str %))` works equally well.
```
(fn[i](first(filter #(apply =(map-indexed -(map int(sort(str %)))))(rest(iterate inc i)))))
```
Ungolfed:
```
(defn f [i]
  (let [is-sorted? #(= 1 (->> % str sort (map int) (map-indexed -) set count))]
    (->> i (iterate inc) rest (filter is-sorted?) first)))
```
[Answer]
## R, 87 bytes
```
f=function(x)`if`(all(diff(sort(as.double(el(strsplit(c(x+1,""),"")))))==1),x+1,f(x+1))
```
As usual when it comes to splitting numbers into digits, R does not have a native way of doing this. Consequently we have to coerce the input into a character, split into a character vector and subsequently convert back to any numeric type.
[Try it online](http://www.r-fiddle.org/#/fiddle?id=HkO8NoHd&version=1)
]