user
Sort an array of numbers (of any convenient size) into ascending order using   Patience sorting.

Related task
:   * Longest increasing subsequence
assistant
(formerly Perl 6)

**Works with**: rakudo version 2015-10-22

```
multi patience(*@deck) {
    my @stacks;
    for @deck -> $card {
        with @stacks.first: $card before *[*-1] -> $stack {
            $stack.push: $card;
        }
        else {
            @stacks.push: [$card];
        }
    }
    gather while @stacks {
        take .pop given min :by(*[*-1]), @stacks;
        @stacks .= grep: +*;
    }
}

say ~patience ^10 . pick(*);

```

Output:

```
0 1 2 3 4 5 6 7 8 9
```