41
3
As described in this question:
Dropsort, designed by David Morgan-Mar, is an example of a linear-time "sorting algorithm" that produces a list that is, in fact, sorted, but contains only some of the original elements. Any element that is not at least as large as the maximum of the elements preceding it is simply removed from the list and discarded.
To use one of their test cases, an input of {1, 2, 5, 4, 3, 7}
yields {1, 2, 5, 7}
, as 4
and 3
are both dropped for being smaller than the previously "sorted" value, 5
.
We don't want "sorting" algorithms, we want them to be the real deal. Therefore, I want you to write a program that, given a list of numbers, outputs a list of DropSorted lists (to be a complete sorting algorithm, we would need to merge these lists, but merging two sorted lists has been done before, and asking you to do it again is pretty much asking two questions, so this question is specifically the "splitting" step of our complete DropSort).
The arrangement and content of our lists is crucial, however. The output of your program must be equivalent to the output of a DropSort, followed by a DropSort of the discarded values, and so on until you have only have a list of sorted chains. Again, borrowing the existing test suite (and adding two more):
Input -> Output
{1, 2, 5, 4, 3, 7} -> {{1, 2, 5, 7}, {4}, {3}}
{10, -1, 12} -> {{10, 12}, {-1}}
{-7, -8, -5, 0, -1, 1} -> {{-7, -5, 0, 1}, {-8, -1}}
{9, 8, 7, 6, 5} -> {{9}, {8}, {7}, {6}, {5}}
{10, 13, 17, 21} -> {{10, 13, 17, 21}}
{10, 10, 10, 9, 10} -> {{10, 10, 10, 10}, {9}} //Note equivalent values aren't dropped
{5, 4, 3, 8, 7, 6} -> {{5, 8}, {4, 7}, {3, 6}}
{0, 2, 5, 4, 0, 7} -> {{0, 2, 5, 7}, {4}, {0}}
You may assume the input is non-empty.
This is code-golf, so standard rules apply!
Can we output like
[5, 4, 3, 8, 7, 6] -> [5, 8], [4,3,7,6]
? – Mr. Xcoder – 2017-08-04T12:59:04.1705@Xcoder, well I don't mind the syntax, but you still have to sort the second list (and split it in this case). Knowing when to stop is part of the challenge ;). And Stewie, I don't really know what to tell you. I saw the DropSort challenge and thought this sounded fun. Any chance you used your time machine to jump ahead and see this question? Just don't use it to see the best answer! – Lord Farquaad – 2017-08-04T13:09:54.600
Note that adding the sorting of the left-overs takes the solutions out of linear time. – ikegami – 2017-08-06T22:51:19.140
Should
{3,4,5,3,4,5,3,4,5}
result in{{3,4,5,5,5},{3,4,4},{3}}
? – QBrute – 2017-08-07T10:00:42.503@QBrute I think that's right. – Lord Farquaad – 2017-08-07T12:35:42.180