Score a dice pair
Roll two dice and sum them. If the two dice match, the pair doubles in value.
- The base score is the sum of both dice.
- When both dice show the same face, the total is doubled.
DicePair(firstRoll: int, secondRoll: int) → int
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public int DicePair(int firstRoll, int secondRoll) {
}
Worked examples
| Call | Result |
|---|---|
DicePair(6, 6) | 24 |
DicePair(3, 4) | 7 |
DicePair(1, 1) | 4 |
DicePair(2, 5) | 7 |
Hint
Sum first, then check for a double.
Reference solution in C#
public int DicePair(int firstRoll, int secondRoll) {
int sum = firstRoll + secondRoll;
if (firstRoll == secondRoll) sum *= 2;
return sum;
}