Problem Statement
Yahtzee is a game played with 5 dice and a score card. The object of the game is to get the best score. A turn consists of rolling the dice and recording the resulting roll in a single place on your score card.
Your score card is divided up as follows:
- 3 of a kind - 3 or more dice the same, scores the face value of ALL the dice.
- 4 of a kind - 4 or more dice the same, scores the face value of ALL the dice.
- full house - 3 dice equal to each other with the other 2 dice equal to each other as well. Scores 25 points.
- small straight - Any 4 of the dice in consecutive order, scores 30 points.
- large straight - All 5 dice in consecutive order, scores 40 points.
- yahtzee - All 5 dice equal to each other, scores 50 points.
- chance - No requirements, scores the face value of ALL the dice.
You are given 7 rolls in a String[] hands. You are to put each of the 7 rolls in exactly one spot in the score card, using only one roll per spot. Each element of hands contains exactly 5 digits and represents the face values of all the dice for one of your rolls. The order of dice is insignificant, so if one of your rolls was four 1's and one 3 it could be "11113" or "13111". You are to return the best possible score you can get.
Definition
- Class:
- YahtzeeBestScore
- Method:
- bestLowerScore
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int bestLowerScore(String[] hands)
- (be sure your method is public)
Notes
- You are allowed to reorder the dice in your hand any way you need to. "12121" can be counted as a full house.
- Straights cannot wrap around. "12346" would count as a small straight, but not a large straight.
- If you have five of the same number it can be used as a full house.
Constraints
- hands will consist of exactly 7 elements.
- Each element in hands will contain exactly 5 digits between '1' and '6', inclusive.
Examples
{ "66666", "66666", "66655", "12345", "12345", "66666", "66666" }Returns: 235
The best possible score.{ "12345", "12345", "12345", "12345", "12345", "12345", "12345" }Returns: 85
Here only the straights and chance score points; all the rest score 0.{ "12121", "12344", "42365", "22222", "66666", "66666", "66666" }Returns: 235
Another perfect score.{ "13144", "32342", "66554", "12321", "65456", "45654", "33445" }Returns: 26
{ "11223", "11223", "11223", "11223", "11223", "11223", "11223" }Returns: 9
The smallest score possible.