Challenge
Given a list of integers, show how gravity sort would be done.
Gravity Sort
In gravity sort, imagine the numbers as rows of asterisks. Then, everything falls, and the new rows will be obviously sorted. Let's look at an example:
[2, 7, 4, 6]
:
**
*******
****
******
-------
**
****
*******
******
-------
** | 2
**** | 4
****** | 6
******* | 7
Notice that this is pretty much just parallelized bubble sort.
Exact Specs
On each iteration, starting from the top row, take every asterisk from the row that doesn't have an asterisk below it, and move it down a row. Keep doing that until the list is sorted.
Input
Input will be a list of strictly positive integers.
Output
For the output, you must output each step. You can choose any two non-whitespace printable ASCII characters, one to be the "asterisks", and one to be the separating "dashes". The rows of asterisks must be separated with a standard newline of some sort (e.g. \n
or \r\f
). The row of dashes must be at least the width of the widest row (otherwise your asterisks are going to fall too far down!). A row of dashes at the very bottom is optional. A trailing newline at the end is permitted. Trailing spaces on each line are permitted.
Test Cases
input will be represented as a list, then output will be listed immediately below. Test cases are separated by a double-newline.
[4, 3, 2, 1]
****
***
**
*
----
***
** *
* *
**
----
**
* *
** *
***
----
*
**
***
****
[6, 4, 2, 5, 3, 1]
******
****
**
*****
***
*
------
****
** **
****
***
* **
***
------
**
****
*** **
* *
***
*****
------
**
***
* *
*** **
****
*****
------
**
*
***
****
******
*****
------
*
**
***
****
*****
******
[8, 4, 2, 1]
********
****
**
*
--------
****
** ****
* **
**
--------
**
* **
** ****
****
--------
*
**
****
********
[2, 7, 4, 6]
**
*******
****
******
-------
**
****
*******
******
-------
**
****
******
*******
Please feel free to correct my test cases if they're wrong, I made them by hand :)
Note: Do not output the sorted list at the end. :)
Scoring
All of your programs will be written on top of each other. You wouldn't want pieces of your program to fall down, so make sure you have the shortest code!
-
s, could we? \$\endgroup\$