TopCoder problem "RPG" used in SRM 171 (Division II Level One)

Problem Statement

    When playing many classic role playing games you often write die rolls in the form "ndx", where n indicates the number of dice of size x to be rolled. A die of size x is an x-sided die that has a distinct number between 1 and x, inclusive, on each of its sides. For example, "2d8" would mean "roll two eight sided dice". Given a String[] representing the dice to roll, return a int[] representing the minimum, maximum, and average die rolls (in that order). Round the value of the average die roll down to the highest integer less than or equal to the actual value. For example, the input {"1d8","3d4","2d6"} would have a minimum of 6 (if all the dice turned up ones), a maximum of 32 (if all the dice turned up their highest values), and an average of 19. The return value would be {6, 32, 19}.


Method signature:int[] dieRolls(String[] dice)
(be sure your method is public)


-dice will contain between 1 and 5 elements, inclusive.
-Each element of dice will be formatted "ndx" (quotes for clarity only), where 'n' is an integer between 1 and 10, inclusive, 'd' is the character 'd', and 'x' is an integer between 2 and 20, inclusive. Neither 'n' nor 'd' will have leading zeros.


Returns: { 3,  18,  10 }
Standard roll for creating characters stats in a popular RPG. The minimum value is when three 1's are rolled, the maximum value is when all 6's are rolled, and the average value is given by 3*(6+1)/2, which rounds down to 10.
Returns: { 4,  18,  11 }
Be careful not to round the value of intermediate results. The average roll of "3d4" is 3*(1+4)/2=7.5, and the average roll of "1d6" is 1*(1+6)/2=3.5. The average of them both is 11, but rounding before adding them together will yield 10, which is incorrect.
Returns: { 26,  330,  178 }
Returns: { 21,  42,  31 }

Problem url:

Problem stats url:


Running Wild


lbackstrom , schveiguy

Problem categories:

Simple Math, String Manipulation