Crack the crag
def crag_score(dice):
Crag (see the Wikipedia page for the scoring table needed in this problem) is a dice game similar to the more popular games of Yahtzee and Poker dice in style and spirit, but with much simpler combinatorics of roll value calculation due to this game using only three dice. Players repeatedly roll
three dice and assign the resulting patterns to scoring categories so that once some roll has been assigned to a category, that category is considered to have been spent and cannot be used again for
any future roll. These tactical choices between safety and risk-taking give this game a little bit more tactical flair on top of merely relying on the favours of Lady Luck for rolling the bones.
Given the list of pips of the three dice of the first roll, this function should compute and return the highest possible score available when all categories of the scoring table are still available for you to choose from, so that all that matters is maximizing this first roll. Note that the examples on
the Wikipedia page show the score that some dice would score in that particular category, which is not necessarily even close to the maximum score in principle attainable with that roll. For example, the roll [1, 1, 1] inefficiently used in the category “Ones” would indeed score only
three points, whereas that same roll would score a whopping 25 points in the more fitting category “Three of a kind”. (The problem “Optimal crag score” later in this collection has you distribute these rolls into distinct categories to maximize the total score.)
This problem ought to be a straightforward exercise on if-else ladders combined with simple sequence management. Your function should be swift and sure to return the correct answer for every one of the 63 = 216 possible pip combinations. However, you will surely design your if-else
structures to handle entire equivalence classes of pip combinations in a single step, so that your entire ladder consists of far fewer than 216 separate steps...
Extracted text: dice Expected result [1, 2, 3] 20 [4, 5, 1] 5 [3, 3, 3] 25 [4, 5, 4] 50 [1, 1, 1] 25 [1, 1, 2] 2