# Three Indistinguishable Dice

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

• I read the question several times and don't have the slightest idea of what it's asking for. – feersum May 18 '16 at 4:24
• In addition to the problem of this challenge being unclear, code golf challenges should score by bytes rather than characters, unless you have a really good reason to override that default. – Mego May 18 '16 at 4:43
• I think I get it. The question is asking us to map from three dice rolls to two dice rolls, with some constraints. – Leaky Nun May 18 '16 at 4:47
• You're not making that with two dice, you're using the three rolls to simulate two rolls. – Nick T May 18 '16 at 17:07
• Both (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. – xnor May 20 '16 at 3:43

# Jelly, 22 20 bytes

6ṗ3Ṣ€ṢðQ€L€Ụịḷi’:6d6‘S


### Background

We map each unordered triplet of dice rolls (listed with respective multiplicities) to an ordered pair of dice rolls in the following fashion:

[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3] -> [1,1]
[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4] -> [1,2]
[1,2,5],[1,2,5],[1,2,5],[1,2,5],[1,2,5],[1,2,5] -> [1,3]
[1,2,6],[1,2,6],[1,2,6],[1,2,6],[1,2,6],[1,2,6] -> [1,4]
[1,3,4],[1,3,4],[1,3,4],[1,3,4],[1,3,4],[1,3,4] -> [1,5]
[1,3,5],[1,3,5],[1,3,5],[1,3,5],[1,3,5],[1,3,5] -> [1,6]
[1,3,6],[1,3,6],[1,3,6],[1,3,6],[1,3,6],[1,3,6] -> [2,1]
[1,4,5],[1,4,5],[1,4,5],[1,4,5],[1,4,5],[1,4,5] -> [2,2]
[1,4,6],[1,4,6],[1,4,6],[1,4,6],[1,4,6],[1,4,6] -> [2,3]
[1,5,6],[1,5,6],[1,5,6],[1,5,6],[1,5,6],[1,5,6] -> [2,4]
[2,3,4],[2,3,4],[2,3,4],[2,3,4],[2,3,4],[2,3,4] -> [2,5]
[2,3,5],[2,3,5],[2,3,5],[2,3,5],[2,3,5],[2,3,5] -> [2,6]
[2,3,6],[2,3,6],[2,3,6],[2,3,6],[2,3,6],[2,3,6] -> [3,1]
[2,4,5],[2,4,5],[2,4,5],[2,4,5],[2,4,5],[2,4,5] -> [3,2]
[2,4,6],[2,4,6],[2,4,6],[2,4,6],[2,4,6],[2,4,6] -> [3,3]
[2,5,6],[2,5,6],[2,5,6],[2,5,6],[2,5,6],[2,5,6] -> [3,4]
[3,4,5],[3,4,5],[3,4,5],[3,4,5],[3,4,5],[3,4,5] -> [3,5]
[3,4,6],[3,4,6],[3,4,6],[3,4,6],[3,4,6],[3,4,6] -> [3,6]
[3,5,6],[3,5,6],[3,5,6],[3,5,6],[3,5,6],[3,5,6] -> [4,1]
[4,5,6],[4,5,6],[4,5,6],[4,5,6],[4,5,6],[4,5,6] -> [4,2]
[1,2,2],[1,2,2],[1,2,2],[1,3,3],[1,3,3],[1,3,3] -> [4,3]
[1,4,4],[1,4,4],[1,4,4],[1,5,5],[1,5,5],[1,5,5] -> [4,4]
[1,6,6],[1,6,6],[1,6,6],[2,3,3],[2,3,3],[2,3,3] -> [4,5]
[2,4,4],[2,4,4],[2,4,4],[2,5,5],[2,5,5],[2,5,5] -> [4,6]
[2,6,6],[2,6,6],[2,6,6],[3,4,4],[3,4,4],[3,4,4] -> [5,1]
[3,5,5],[3,5,5],[3,5,5],[3,6,6],[3,6,6],[3,6,6] -> [5,2]
[4,5,5],[4,5,5],[4,5,5],[4,6,6],[4,6,6],[4,6,6] -> [5,3]
[5,6,6],[5,6,6],[5,6,6],[1,1,2],[1,1,2],[1,1,2] -> [5,4]
[1,1,3],[1,1,3],[1,1,3],[1,1,4],[1,1,4],[1,1,4] -> [5,5]
[1,1,5],[1,1,5],[1,1,5],[1,1,6],[1,1,6],[1,1,6] -> [5,6]
[2,2,3],[2,2,3],[2,2,3],[2,2,4],[2,2,4],[2,2,4] -> [6,1]
[2,2,5],[2,2,5],[2,2,5],[2,2,6],[2,2,6],[2,2,6] -> [6,2]
[3,3,4],[3,3,4],[3,3,4],[3,3,5],[3,3,5],[3,3,5] -> [6,3]
[3,3,6],[3,3,6],[3,3,6],[4,4,5],[4,4,5],[4,4,5] -> [6,4]
[4,4,6],[4,4,6],[4,4,6],[5,5,6],[5,5,6],[5,5,6] -> [6,5]
[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5],[6,6,6] -> [6,6]


This makes all outcomes equiprobable.

### How it works

6ṗ3Ṣ€ṢðĠ€Ụịḷi’:6d6‘S  Main link. Argument: D (three dice rolls, sorted)

6ṗ3                     Generate lists of length 3 over [1, 2, 3, 4, 5, 6].
Ṣ€                   Sort each triplet.
Ṣ                  Sort the list of triplets.
ð                 Begin a new, dyadic chain.
Arguments: A (list of triplets), D
Ġ€               Group each; group the indices of each triplet by the
the corresponding values.
For a triplet [a, b, c], this yields:
[[1], [2], [3]] if a < b < c
[[1], [2, 3]]   if a < b = c
[[1, 2], [3]]   if a = b < c
[[1, 2, 3]]     if a = b = c
Ụ            Grade up; sort the indices of A by those 2D lists.
ịḷ          Retrieve the elements of A at those indices.
This sorts A as in the previous section.
i         Find the (1-based) index of D.
’        Decrement to get the 0-based index.
:6      Divide the index by 6, rounding down.
d6    Divmod; return quotient and remainder of division by 6.
‘   Increment to map [0, ..., 5] to [1, ..., 6].
S  Sum the results.


# CJam, 25 24 bytes

6Zm*{$ez}$q~:(a#6bW2t1b


This is a port of my Jelly answer.

Thanks to @jimmy23013 for golfing off 1 byte!

• Well, I should have read your code before posting an answer... But some simple golf: 6bW2t1b. – jimmy23013 May 20 '16 at 16:36
• @jimmy23013 Nice. Thank you! – Dennis May 20 '16 at 16:45

# Pyth, 41 27 bytes

JSSM^S6 3+2sPtj+216xo/JNJQ6


10 random testcases

Confirmation of validity.

### Conversion table:

2: [111, 222, 333, 444, 555, 666]
3: [112, 113, 223, 224]
4: [114, 115, 225, 226, 355, 366]
5: [116, 122, 125, 233, 244, 445, 446]
6: [126, 133, 144, 146, 255, 266, 455, 466]
7: [134, 155, 156, 166, 246, 334, 335, 556, 566]
8: [123, 135, 234, 256, 336, 344]
9: [124, 136, 235, 345]
10: [145, 236, 346]
11: [245, 356]
12: [456]


## Previous 41-byte solution:

I need to golf this...

JSM^S6 3+2f/@co,/JNNJ.u+NY*R6t+S5_S6 6TQ0


Try it online!

### Conversion table:

2: [111, 222, 333, 444, 555, 666]

3: [112, 113, 114, 115]

4: [116, 122, 133, 144, 155, 166]

5: [223, 224, 225, 226, 233, 244, 255, 266]

6: [334, 335, 336, 344, 355, 366, 445, 446, 455, 466]

7: [556, 566, 123, 124, 125, 126, 134]

8: [135, 136, 145, 146, 156]

9: [234, 235, 236, 245]

10: [246, 256, 345]

11: [346, 356]

12: [456]


# CJam, 37 35 bytes

Probably not golfed well. But beat Pyth.

8aq~\;[_2$>8+@7+@:U2+1$([8U4\$7]])er
`

Try it here.

• I suggest you change that description. – Leaky Nun May 21 '16 at 3:25