12
2
Challenge
Given a string input, output the demolished version of it.
The Process
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
1
and(height of the column of characters) - 1
and 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
1
larger 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
1
character 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
Rules
- 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!
1I would doubt if random is really necessary here – Keyu Gan – 2017-10-13T01:51:12.023
@KeyuGan I think the challenge would be fairly trivial if people had to select a fixed number of characters and alternated left/right. – JungHwan Min – 2017-10-13T02:22:12.437
4We still can say that 4 is random and returned by a fair dice roll – my pronoun is monicareinstate – 2017-10-13T04:02:39.177
@someone
4
would make the output deterministic, i.e. not "random." Edited the rules to make that explicit. – JungHwan Min – 2017-10-13T05:00:17.500@someone are you referring at 4 because of XKCD?
– Giacomo Garabello – 2017-10-13T10:03:51.890Yes, but that reference is not the main idea of the comment. – my pronoun is monicareinstate – 2017-10-13T10:18:07.500