What is the dice result probability curve of 4d6kh3r1, but with an exception rule?

140 Views Asked by At

So the equation is four 6-sided dice, keep the highest three results of the four results, and reroll any ones rolled. However the exception comes in where the reroll won't happen if there are already three results higher than a one, so only if there are two 1s rolled.

I am not certain if this is the right stackexchange for this question, but i can't find any auto statistic calculators online that can apply this exception. Anyone's know what the average and deviation would be?

An example below:

(4, 2, 4, 1) = 10 -> the 1 is dropped and not rerolled because there are 3 results higher than 1

(5, 2, 2, 4) = 11 -> one of the 2s is dropped and no rerolls because a 1 was not rolled

(1, 2, 2, 1, [1, 6]) = 10 -> two 1s were rolled and got rerolled into a 1 and 6, the new 1 is not rolled because you now have 3 results higher than 1.

1

There are 1 best solutions below

0
On BEST ANSWER

This can be expressed using my Icepool library as such:

from icepool import d, Reroll

def reroll_ones_if_multiple(roll):
    num_ones = roll.count(1)
    if num_ones <= 1:
        # Not enough ones to trigger reroll.
        return roll
    # Reroll the ones.
    rerolled = d(6).pool(num_ones).expand()
    # Remove the all ones outcome to prevent an infinite loop.
    # reroll() rerolls the lowest outcome by default.
    rerolled = rerolled.reroll()
    # Reroll any remaining ones (if appropriate).
    rerolled = rerolled.sub(reroll_ones_if_multiple)
    def gather(rerolled_outcome):
        all_rolls = roll[num_ones:] + rerolled_outcome
        return tuple(sorted(all_rolls))
    return rerolled.sub(gather)

proposed = reroll_ones_if_multiple((1, 1, 1, 1)).sub(lambda x: sum(x[1:]))

print(f'Mean: {proposed.mean()} SD: {proposed.standard_deviation()}')

output(proposed, "proposed")
output(d(6).keep_highest(4, 3), "4d6kh3")
output(d(6).keep_highest(5, 3), "5d6kh3")

Result:

Mean: 12.824477686989315 SD: 2.5054380002701975

Die with denominator 9744875

Outcome Quantity Probability
3 0 0.000000%
4 0 0.000000%
5 0 0.000000%
6 42091 0.431930%
7 135240 1.387806%
8 288414 2.959648%
9 519547 5.331490%
10 837606 8.595349%
11 1116318 11.455437%
12 1337749 13.727718%
13 1439130 14.768070%
14 1393560 14.300440%
15 1147237 11.772722%
16 826434 8.480704%
17 475986 4.884475%
18 185563 1.904211%