YahtzeeBestScore
SRM 262 · 2005-09-09 · by Olexiy
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
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.
{ "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.
{ "11111", "22222", "33333", "44444", "55555", "66666", "12345" }
Returns: 190
{ "13144", "32342", "66554", "12321", "65456", "45654", "33445" }
Returns: 26
{ "11223", "11223", "11223", "11223", "11223", "11223", "11223" }
Returns: 9
The smallest score possible.
Submissions are judged against all 60 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class YahtzeeBestScore with a public method int bestLowerScore(vector<string> hands) · 60 test cases · 2 s / 256 MB per case