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
Jelly, 22 20 bytes

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


Try it online! or simulate all 216 outcomes.

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] -&gt; [1,1]
[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4] -&gt; [1,2]
[1,2,5],[1,2,5],[1,2,5],[1,2,5],[1,2,5],[1,2,5] -&gt; [1,3]
[1,2,6],[1,2,6],[1,2,6],[1,2,6],[1,2,6],[1,2,6] -&gt; [1,4]
[1,3,4],[1,3,4],[1,3,4],[1,3,4],[1,3,4],[1,3,4] -&gt; [1,5]
[1,3,5],[1,3,5],[1,3,5],[1,3,5],[1,3,5],[1,3,5] -&gt; [1,6]
[1,3,6],[1,3,6],[1,3,6],[1,3,6],[1,3,6],[1,3,6] -&gt; [2,1]
[1,4,5],[1,4,5],[1,4,5],[1,4,5],[1,4,5],[1,4,5] -&gt; [2,2]
[1,4,6],[1,4,6],[1,4,6],[1,4,6],[1,4,6],[1,4,6] -&gt; [2,3]
[1,5,6],[1,5,6],[1,5,6],[1,5,6],[1,5,6],[1,5,6] -&gt; [2,4]
[2,3,4],[2,3,4],[2,3,4],[2,3,4],[2,3,4],[2,3,4] -&gt; [2,5]
[2,3,5],[2,3,5],[2,3,5],[2,3,5],[2,3,5],[2,3,5] -&gt; [2,6]
[2,3,6],[2,3,6],[2,3,6],[2,3,6],[2,3,6],[2,3,6] -&gt; [3,1]
[2,4,5],[2,4,5],[2,4,5],[2,4,5],[2,4,5],[2,4,5] -&gt; [3,2]
[2,4,6],[2,4,6],[2,4,6],[2,4,6],[2,4,6],[2,4,6] -&gt; [3,3]
[2,5,6],[2,5,6],[2,5,6],[2,5,6],[2,5,6],[2,5,6] -&gt; [3,4]
[3,4,5],[3,4,5],[3,4,5],[3,4,5],[3,4,5],[3,4,5] -&gt; [3,5]
[3,4,6],[3,4,6],[3,4,6],[3,4,6],[3,4,6],[3,4,6] -&gt; [3,6]
[3,5,6],[3,5,6],[3,5,6],[3,5,6],[3,5,6],[3,5,6] -&gt; [4,1]
[4,5,6],[4,5,6],[4,5,6],[4,5,6],[4,5,6],[4,5,6] -&gt; [4,2]
[1,2,2],[1,2,2],[1,2,2],[1,3,3],[1,3,3],[1,3,3] -&gt; [4,3]
[1,4,4],[1,4,4],[1,4,4],[1,5,5],[1,5,5],[1,5,5] -&gt; [4,4]
[1,6,6],[1,6,6],[1,6,6],[2,3,3],[2,3,3],[2,3,3] -&gt; [4,5]
[2,4,4],[2,4,4],[2,4,4],[2,5,5],[2,5,5],[2,5,5] -&gt; [4,6]
[2,6,6],[2,6,6],[2,6,6],[3,4,4],[3,4,4],[3,4,4] -&gt; [5,1]
[3,5,5],[3,5,5],[3,5,5],[3,6,6],[3,6,6],[3,6,6] -&gt; [5,2]
[4,5,5],[4,5,5],[4,5,5],[4,6,6],[4,6,6],[4,6,6] -&gt; [5,3]
[5,6,6],[5,6,6],[5,6,6],[1,1,2],[1,1,2],[1,1,2] -&gt; [5,4]
[1,1,3],[1,1,3],[1,1,3],[1,1,4],[1,1,4],[1,1,4] -&gt; [5,5]
[1,1,5],[1,1,5],[1,1,5],[1,1,6],[1,1,6],[1,1,6] -&gt; [5,6]
[2,2,3],[2,2,3],[2,2,3],[2,2,4],[2,2,4],[2,2,4] -&gt; [6,1]
[2,2,5],[2,2,5],[2,2,5],[2,2,6],[2,2,6],[2,2,6] -&gt; [6,2]
[3,3,4],[3,3,4],[3,3,4],[3,3,5],[3,3,5],[3,3,5] -&gt; [6,3]
[3,3,6],[3,3,6],[3,3,6],[4,4,5],[4,4,5],[4,4,5] -&gt; [6,4]
[4,4,6],[4,4,6],[4,4,6],[5,5,6],[5,5,6],[5,5,6] -&gt; [6,5]
[1,1,1],[2,2,2],[3,3,3],[4,4,4],[5,5,5],[6,6,6] -&gt; [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 &lt; b &lt; c
                          [[1], [2, 3]]   if a &lt; b = c
                          [[1, 2], [3]]   if a = b &lt; 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.