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.


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.


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


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 , so shortest code in bytes wins!

  • 1
    \$\begingroup\$ Does "4 values in any format you choose" include taking them in a different order? \$\endgroup\$ Jan 4, 2016 at 0:03
  • 1
    \$\begingroup\$ Or something like [12, 14, 8], 3? \$\endgroup\$ Jan 4, 2016 at 0:04
  • \$\begingroup\$ I thought i had the order included, its in now. Mixed inputs are allowed as well. \$\endgroup\$
    – Eumel
    Jan 4, 2016 at 8:30

2 Answers 2


Pyth - 21 20 19 bytes

Saved 1 bytes thanks to @ThomasKwa


Test Suite.

  • \$\begingroup\$ Pyth is so good... This is APL's type of question, and I only have 27 in APL. \$\endgroup\$
    – lirtosiast
    Jan 3, 2016 at 23:18
  • \$\begingroup\$ the order of the input was suppoesed to be stat,stat,stat,TV i did only specify that now though. However if you can modify that easily that would be nice. Could you put in an explanation? \$\endgroup\$
    – Eumel
    Jan 4, 2016 at 8:38
  • \$\begingroup\$ @Eumel sure, changing the order shouldn't be as problem, I'm on a phone right now, I'll do it when I get home. \$\endgroup\$
    – Maltysen
    Jan 4, 2016 at 19:13

Dyalog APL, 28 bytes


This approach is the same as @Maltysen's. We can't be sure of 0.5% accuracy if we just draw a few thousand random dice rolls, so we instead take the average over all possible rolls. This takes the three stats as the left argument, and the talent value on the right.

Try it here!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.