Given three dice rolls (integer values from 1-6) in sorted order (so as to be indistinguishable), convert them to the sum of two fair dice with an identical distribution.
The answer for three to one is summing them all, modulo 6. The end-result is a perfectly flat distribution, where each of the six numbers are equally likely (just like a single die).
It's easy to do this for three-to-one, by summing them all modulo 6. The end-result is a perfectly flat distribution, where each of the six numbers are equally likely (just like a single die). Your challenge is to do the same for three-to-two.
Inspired by standupmath's The Three Indistinguishable Dice Puzzle. A follow-up "solution" video was also posted, but arguing about "elegance" of one way or another is a bit subjective. Counting characters isn't. :D
Instructions
Write a program or function that accepts three sorted integers/digits, 1-6, and outputs or returns a single integer, 2-12, such that, for the 216 possible inputs, the outputs are distributed as:
222222
333333333333
444444444444444444
555555555555555555555555
666666666666666666666666666666
777777777777777777777777777777777777
888888888888888888888888888888
999999999999999999999999
AAAAAAAAAAAAAAAAAA
BBBBBBBBBBBB
CCCCCC
(I've used hex to keep to single characters; decimal output is fine)
Because the dice are indistinguishable, there is no intrinsic order to them, hence the sorted input. You cannot simply "drop the third" because that would be ambiguous.
Details
- Score is the length of the program in bytes
- The program can be a function that's called somehow, or executable script that reads from stdin, or whatever's convienent.
- No "rerolling" by getting entropy from another source
Example (and test)
Rather than doing any sort of probabilistic testing, it's easy enough to rip through the 216 (6³) cases of all the three dice and assert that your function returns each value as many times as it should. It will be called with identical parameters (e.g. the cases 1, 2, 3
and 3, 2, 1
, ... are presumed indistinguishable and are (arbitrarily) converted to 1, 2, 3
).
An example answer (extremely brute-force and inefficient) and test suite is provided below in Python. Hopefully the test bits are clear enough to port to your language of choice, though doing stdin/stdout would be a bit different. The testing code is just for testing and not scored (though if you want to provide it for other users of your language or I/O method, that might be useful).
# 6x6 lists of numbers with digits sorted
LUT = [
[[124], [133, 166], [346], [223, 355], [256], [115, 445]],
[[233, 266], [125], [224, 455], [134], [116, 446], [356]],
[[126], [111, 333, 555, 225], [234], [144, 366], [456], [135]],
[[112, 244], [235], [334, 466], [145], [226, 556], [136]],
[[146], [122, 155], [236], [113, 344], [245], [335, 566]],
[[246], [123], [114, 336], [345], [222, 444, 666, 255], [156]],
]
def three2two(rolls):
look_for = int('{}{}{}'.format(*sorted(rolls)))
for i in range(6):
for j in range(6):
if look_for in LUT[i][j]:
return i + j + 2
# fair distribution of the sum of two dice multiplied by 6 (because each should be hit 6x)
expected_counts = {
2: 6, 12: 6,
3: 12, 11: 12,
4: 18, 10: 18,
5: 24, 9: 24,
6: 30, 8: 30,
7: 36,
}
d = [1, 2, 3, 4, 5, 6]
for i in d:
for j in d:
for k in d:
ijk = sorted([i, j, k])
result = three2two(ijk)
expected_counts[result] -= 1
for key in expected_counts:
assert expected_counts[key] == 0
(a+b+c)%6+1
and(a*b*c)%7
convert a triple of unordered dice to a uniform single die roll, but unfortunately are not probabilistically independent. \$\endgroup\$