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
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.
{ "11111", "22222", "33333", "44444", "55555", "66666", "12345" }
Returns: 190
{ "13144", "32342", "66554", "12321", "65456", "45654", "33445" }
Returns: 26
{ "66666", "55666", "54321", "65431", "11223", "22334", "33445" }
Returns: 167
{ "11122", "22233", "33344", "44455", "55566", "66611", "66666" }
Returns: 124
{ "52141", "32142", "41114", "53444", "25222", "52433", "42441" }
Returns: 105
{ "11223", "11223", "11223", "11223", "11223", "11223", "11223" }
Returns: 9
The smallest score possible.
{ "11111", "11111", "11111", "11111", "11111", "11111", "11111" }
Returns: 90
{ "22222", "22222", "22222", "22222", "22222", "22222", "22222" }
Returns: 105
{ "12344", "32234", "22333", "56565", "12345", "22222", "11111" }
Returns: 196
{ "11115", "12345", "12345", "33365", "12345", "55555", "66666" }
Returns: 189
{ "55222", "46322", "11334", "36332", "32343", "12122", "33224" }
Returns: 59
{ "11112", "22223", "33334", "44445", "55556", "66661", "11111" }
Returns: 122
{ "11111", "12345", "12345", "33333", "11112", "11223", "22334" }
Returns: 165
{ "62334", "43221", "54321", "33222", "33344", "11111", "11111" }
Returns: 185
{ "11122", "22233", "33344", "44455", "55566", "66611", "11122" }
Returns: 74
{ "13344", "22343", "22322", "13222", "11111", "12122", "65432" }
Returns: 151
{ "32533", "44421", "64366", "32111", "22234", "56455", "66615" }
Returns: 50
{ "11111", "11111", "11111", "11111", "11111", "11111", "11111" }
Returns: 90
{ "11111", "11111", "11111", "11111", "12345", "12345", "22222" }
Returns: 165
{ "32114", "32211", "23422", "44322", "11456", "65533", "54554" }
Returns: 90
{ "45666", "23444", "24212", "12344", "43533", "22234", "32246" }
Returns: 75
{ "53535", "12121", "64646", "25252", "53535", "21212", "34343" }
Returns: 72
{ "66266", "44544", "11112", "33363", "22221", "55515", "64666" }
Returns: 75
{ "66661", "66662", "66663", "66664", "66665", "66666", "66666" }
Returns: 159
{ "66611", "66622", "66633", "66644", "66655", "66666", "66666" }
Returns: 159
{ "23456", "12345", "23456", "12345", "12345", "12345", "12345" }
Returns: 90
{ "54422", "23344", "66554", "33445", "11223", "33661", "23234" }
Returns: 26
{ "55544", "33361", "12354", "66666", "12344", "55555", "44444" }
Returns: 216
{"41456", "16246", "45241", "26215", "34141", "45316", "32431"}
Returns: 50
{"62623", "53646", "56316", "24325", "15533", "51435", "46615"}
Returns: 54
{"42121", "43562", "61222", "12141", "61133", "54152", "14663"}
Returns: 73
{"15641", "54665", "55511", "62466", "44215", "26651", "32444"}
Returns: 75
{"55512", "33133", "24224", "64215", "36465", "33224", "62231"}
Returns: 104
{"36635", "65145", "21622", "21232", "44314", "23432", "14142"}
Returns: 39
{"42553", "13521", "52522", "36653", "16221", "24363", "52446"}
Returns: 78
{"55221", "13112", "26646", "26336", "41141", "31564", "21534"}
Returns: 139
{"31426", "46432", "11541", "46126", "46635", "43643", "31156"}
Returns: 66
{"43653", "53256", "35123", "54341", "33332", "32216", "15244"}
Returns: 65
{"35643", "14215", "44346", "15544", "26223", "12661", "15311"}
Returns: 70
{"26466", "24512", "43614", "51246", "43163", "63426", "51332"}
Returns: 45
{"41235", "51622", "46542", "23511", "53131", "12344", "63614"}
Returns: 91
{"41145", "23563", "45115", "63355", "46444", "31141", "51151"}
Returns: 79
{"16461", "56411", "32332", "43624", "61442", "21455", "31312"}
Returns: 44
{"31526", "12644", "15535", "51421", "52514", "45343", "22414"}
Returns: 38
{"44532", "64452", "43442", "53221", "65623", "61215", "54153"}
Returns: 69
{"36315", "42515", "24555", "45664", "23214", "66243", "31643"}
Returns: 76
{"54431", "64523", "53611", "21323", "56115", "32132", "63316"}
Returns: 59
{"11223", "11223", "11223", "11223", "11223", "11111", "11111" }
Returns: 84
{"11111", "11111", "11111", "11111", "11111", "11111", "11111" }
Returns: 90
{"66666", "66666", "66655", "54321", "54321", "66666", "66666" }
Returns: 235
{"66666", "11111", "66655", "12345", "12345", "11111", "11111" }
Returns: 208
{"66666", "66666", "66666", "66666", "66666", "66666", "66666" }
Returns: 165
{"11123", "11123", "11123", "11123", "11123", "11123", "11123" }
Returns: 16
{"11112", "11112", "11112", "11112", "11112", "11112", "11112" }
Returns: 18
{"12234", "12234", "12234", "12234", "12234", "12234", "12234" }
Returns: 42
{"66666", "66666", "66655", "12345", "12345", "66666", "66666" }
Returns: 235
{"66644", "12346", "12346", "12346", "12346", "12346", "12346" }
Returns: 72