Given a string input, output the demolished version of it.
P r Pr r o o o g g g r r r rogr r a -> a -> a -> a -> a -> -> -> -> -> m m m m m m m m m m mmar m i i i i i i i mi m n n n n gn gn gn gn gni mgni g g Pg Pg roPg roPg roPgmar roPgmar roPgmar roPgmar
- Place the string vertically.
- Select a random integer between
(height of the column of characters) - 1and a random direction (left or right).
- Rotate that number of characters in that direction (if those spaces are unoccupied go to step 4; if not, go back to step 2).
- Let those characters fall due to gravity.
- Repeat until the height of the column of characters is at most
1larger than the height of the columns next to it (i.e. it becomes impossible to further demolish ("steps 2-4") the column).
- If there is another column of characters that is more than
1character taller than one or more of its surrounding columns (i.e. demolish-able), repeatedly demolish that column until it is no longer demolish-able. If there are multiple demolish-able columns, completely demolish the tallest column (if there are multiple tallest columns, completely demolish the leftmost one).
- Repeat until all columns are no longer demolish-able.
If there are space characters in the input, demolish those first, all at once.
C o d e -> oC -> -> ... de G G G o o o l l l f f defoC
- Standard loopholes are forbidden.
- Trailing and leading newlines are allowed.
- Your program may either print or return a string/equivalent.
- The output must be non-deterministic (unless the input is not demolish-able).
This is code-golf, so the submissions with the smallest byte counts in their languages win!