When playing an RPG such as Dungeons & Dragons, Pathfinder, or Paranoia, players each need a set of dice. You are hosting one such game this weekend, and some of the friends you invited have never played an RPG before. They don't want to commit to buying their own set of dice until they know they'll use them (if they want to keep playing). This is fine and dandy with you, but you're not going to let them use your lucky set of dice that you pre-rolled the ones out of...
...so you are going to write a program or function that simulates the dice-rolling for them.
Dice are often described in the format:
<How many dice>d<Number of sides> A common set of dice for RPG use includes:
2d10 (also used as
Your code must accept a string of any number of the above dice specifiers separated by spaces or commas as input. It must then output the result of each individual die-roll separated by spaces, with parentheses around groups; then the sum of each grouping on the next line, separated by spaces; and finally, the total sum on a third line. Single-die groups don't have parentheses. Dice must always be in the same order as provided in the input.
The percent die, whether written as
1d100, should be calculated as the concatenation of
2d10 (just 2 rolls, each from 0-9, but a final result of zero is instead counted as 100), but each occurrence will be displayed as if a single roll.
2d10 in the input will still be treated and displayed as 2 individual rolls. It can be easy to get confused by percent dice, here's a good explanation.
Edit: To clarify, the number of rolls may exceed 9.
1d4 3d6 2d8
3 (1 5 2) (8 4) 3 8 12 23
1d20 1d% 2d10 1d100 5d12
16 100 (9 4) 42 (5 1 7 7 11) 16 100 13 42 31 204
- Standard loopholes are disallowed.
- Printable ASCII in code, only.
- code-golf - shortest code wins.
- -10 bytes if the rolls are actually random, rather than pseudo-random.