public class DiceUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
SIDES
The number of sides on a standard die.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
isFullHouse(List<Integer> dice)
Returns true if a list of exactly 5 dice is a full house, and
false otherwise.
|
static boolean |
isSorted(List<Integer> dice)
Returns true if a list of dice is sorted in ascending order,
and false otherwise.
|
static int |
median(List<Integer> dice)
Given a list of dice sorted in ascending order, returns the
median value of the dice in the list.
|
static int |
neededToRoll(int value)
Returns the smallest number of dice required to roll the
given value.
|
public static final int SIDES
public static int neededToRoll(int value)
value
- a valuepublic static int median(List<Integer> dice)
dice returns ---------------------------- [2, 2, 3] 2 [3, 4, 5, 5] 4 [1, 2, 3, 4, 4] 3 [1, 1, 4, 5, 5, 6] 4
dice
- a list of diceIllegalArgumentException
- if the list of dice is emptypublic static boolean isSorted(List<Integer> dice)
dice returns ---------------------------- [] true [3] true [1, 4] true [1, 2, 2] true [3, 2] false [1, 6, 4] false [1, 2, 5, 3] false [4, 4, 4, 4] true
dice
- a list of dicepublic static boolean isFullHouse(List<Integer> dice)
5 dice form a full house if exactly 2 dice have the same value (form a pair) and the remaining 3 dice have the same value (form a three-of-a-kind) which is different than the value of the pair. For example, the following lists are all full houses:
[1, 1, 1, 5, 5] two 5s and three 1s [4, 4, 4, 2, 2] two 2s and three 4s [6, 3, 3, 6, 3] two 6s and three 3s
but the list:
[2, 2, 2, 2, 2] two 2s and three 2s???
is not considered a full house.
dice
- a list of dice