Some friends and I have played some DSA (a mainly german tabletop RPG much like D&D). I was wondering what the chance on passing rolls are, so you will have to write some code to calculate it.
Your character is defined by stats (from 8 to 14) and (TV) Talent values (0 to 21). For now we will use climbing as an example.
Talent tests
A talent (climbing) looks like this: (Courage-Dexterity-Strength) TV: 7. To test a character on a talent you roll on these stats with a 20-sided dice and try to get below or equal to the stat, if you do that well. If not, you can use your TV points to reduce the roll with a ratio of 1:1.
Example
A hunter with courage 12, dexterity 13 and strength 14 is trying to climb a tree, his TV is 7.
He rolls a 3, the value is below 12 so he passed that roll.
Then he rolls a 17, 17 is 4 more than 13, so 4 TV get used up with 3 left.
For the last roll you get a 14, spot on passed.
All rolls are passed and the hunter managed to climb the tree, 3 TV are left.
Input
4 values in any format you choose, taken from the standard input of your language. It has to be in this order though.
E.g. 12 13 14 7
or 12,13,14,7
or as an array {12,13,14,7} or mixed [12, 14, 8], 3
Output
The chance of how often the rolls pass.
E.g. (for values above)0.803
12,14,8,3 = 0.322
11,11,12,11 = 0.840
For the bonus: Again formating is not the issue here, output it however you like but in following order:
failed/with 0/with 1/with 2/with 3/with 4/with 5/with 6/with 7
and so on until no TV is left.
12,13,14,7 = 0.197/0.075/0.089/0.084/0.078/0.073/0.068/0.063/0.273
12,14,8,3 = 0.678/0.056/0.051/0.047/0.168
Challenge and rules and bonus
You shall find out given the input the chance to pass the rolls to a +- 0.5% accuracy.
-20% if your program also outputs the chances to pass with
n
TV (see output).This is code-golf, so shortest code in bytes wins!
[12, 14, 8], 3
? \$\endgroup\$