Lucky dice rolls
In pen and paper roleplaying games dice are used for various chance calculations. The usual way to describe a roll is \$n\textbf{d}k\$ where \$n\$ is the number of dice and \$k\$ is the number of faces on a die. For example \$3d6\$ means that you need to roll the classical 6-sided die 3 times (or roll 3 dice at the same time). Both \$n\$ and \$k\$ are positive integers. Each die's output value ranges from 1 to \$k\$.
Usually the values are then summed and they are used for various game mechanics like chance to hit something or damage calculations.
A lucky roll will mean that you have Fortuna's favor on your side (or against you). Luckiness is an integer number that increases (or decreases) the sum in the following way. The roll is modified to \${(n+|luck|)}\textbf{d}{k}\$ and the sum will be the \$n\$ best (or worst) values. Each die is fair, so they will have the same probability for the outcome of the possible values per die.
The \$luck\$ can be a negative number, in this case you need to get the \$n\$ worst values for the sum.
Input
The integer values for \$n,k,luck\$ in any way.
Output
The expected value for the sum of the (un)lucky roll. The expected value is \$\sum{x_{i} p_{i}}\$ where \$x_{i}\$ is the possible outcome of the sum and \$p_{i}\$ is the probability for \$x_{i}\$ occuring, and \$i\$ indexes all possible outcomes. The output value can be float or rational number, at least 3 decimal places of accuracy or a fraction of two integer numbers, whichever suits your program better.
Examples
n,k,luck expected value
1,6,0 3.5
2,6,0 7
2,6,-1 5.54166
2,6,1 8.45833
2,6,-5 3.34854
2,10,-1 8.525
2,10,1 13.475
6,2,15 11.98223
6,2,-15 6.01776
Scoring
Shortest code in bytes wins.
Other
With this mechanic you essentially create fake dice using only fair dice. I wonder if there is a nice formula to calculate this mathematically.
Good luck! ;)
8.458333333333
as expected answer? Rounding should not result in a trailing 4. \$\endgroup\$1827 / 216
to8.458333333333334
. \$\endgroup\$