31
2
Inspired by this chat mini-challenge.
Given a string as input (ASCII printable characters only), output the string with the letters "raining" down. Each letter must be a random number of lines downward (random between 0 and the length of the string, each having non-zero probability), and only one character per column. All possible outputs must again have a non-zero probability of occurring.
That's maybe a little confusing, so here's an example (taken from that CMC):
Hello World
d
H
o
llo
l
W
e
r
Note how the H is one space down, the d is zero down, and the llo all happen to line up. The r is the farthest down, at 9, but is still less than the string length away from the top. This is just one example, there are dozens of other possibilities for input Hello World.
Other examples could be:
test
t
e
s
t
PP&CG
& G
P
P C
- Input and output can be given by any convenient method.
- The input is guaranteed non-empty (i.e., you'll never receive
""as input). - You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately (e.g., feel free to pad as a rectangle).
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
2Thought this was going to involve animation when I read the title. Have we had an animated version of this? – Shaggy – 2019-04-12T22:22:03.170
@Shaggy Not that I've seen or been able to find. – AdmBorkBork – 2019-04-13T00:52:49.063
"Any amount of extraneous whitespace is acceptable" - does that include a leading line of whitespace? – Jonathan Allan – 2019-04-13T19:52:22.533
I know we have had one based on the Matrix code, but good luck finding it with those 2 keywords! Do you mind if I Sandbox the idea? – Shaggy – 2019-04-13T19:57:29.877
What is the maximum input size answers need to implement? I'm seeing many people use random functions that use "pseudo-random" in the backendground, and certain input words are larger than the size of the seed used in those generators, and they will fail the " All possible outputs must again have a non-zero probability of occurring." constraint you have specified – Ferrybig – 2019-04-13T20:33:38.727
@JonathanAllan Leading whitespace is fine. – AdmBorkBork – 2019-04-15T12:32:29.360
@Shaggy Go for it! – AdmBorkBork – 2019-04-15T12:32:39.270
@Ferrybig One of the standards of the site is you can assume your language doesn't have limitations (e.g., an unlimited-memory computer), in order to implement your designed algorithm. Same should apply here with regard to the size of the PRNG (e.g., 64-bit), so long as the algorithm presented isn't based on that limitation. So far, I've not seen anything wrong with any of the submissions. – AdmBorkBork – 2019-04-15T12:36:28.770