27
3
Let's see how good your language of choice is at selective randomness.
Given 4 characters, A
, B
, C
, and D
, or a string of 4 characters ABCD
as input, output one of the characters with the following probabilities:
A
should have a 1/8 (12.5%) chance to be chosenB
should have a 3/8 (37.5%) chance to be chosenC
should have a 2/8 (25%) chance to be chosenD
should have a 2/8 (25%) chance to be chosen
This is in-line with the following Plinko machine layout:
^
^ ^
^ ^ ^
A B \ /
^
C D
Your answer must make a genuine attempt at respecting the probabilities described. A proper explanation of how probabilities are computed in your answer (and why they respect the specs, disregarding pseudo-randomness and big numbers problems) is sufficient.
Scoring
This is code-golf so fewest bytes in each language wins!
Can we assume the built-in random function in our language of choice is random? – Mr. Xcoder – 2017-07-17T15:14:37.393
@Mr.Xcoder within reason, yes. – Skidsdev – 2017-07-17T15:21:58.797
So, for clarity, the input is always exactly 4 characters, and it should assign probabilities to each in accordance with exactly the provided Plinko layout? Generating Plinko layouts or simulating them is entirely unnecessary as long as the probabilities are correct within the accuracy provided by your random source? – Kamil Drakari – 2017-07-17T16:15:21.440
1@KamilDrakari correct. – Skidsdev – 2017-07-17T16:27:15.147
2Not very useful due to its length, but I found out that the expression
ceil(abs(i - 6)/ 2.0)
will map an index from0-7
to an index from0-3
with the appropriate distribution (0 111 22 33
) for this challenge... – Socratic Phoenix – 2017-07-17T17:18:31.207Can I do a spin-off of this, potentially accepting a well-formed plinko machine to do the output? – Magic Octopus Urn – 2018-03-13T21:17:30.280
@MagicOctopusUrn Provided it's different enough to not be dupe hammered, go for it! – Skidsdev – 2018-03-15T10:00:27.987