r/dailyprogrammer_ideas • • Aug 07 '19

[Easy] Yahtzee scoring

Description

Yahtzee is a dice game where the objective is to score points by rolling five dice to make certain combinations.

The Yahtzee scorecard contains 13 different category boxes and in each round, after rolling the five dice, the player must choose one of these categories. The score entered in the box depends on how well the five dice match the scoring rule for the category.

The categories and their corresponding scores are as follows:

CategoryRequirementScoreExample
AcesAny combinationSum of dice with the number 1[1-1-1-3-4] scores 3
TwosAny combinationSum of dice with the number 2[2-2-2-5-6] scores 6
ThreesAny combinationSum of dice with the number 3[3-3-3-3-4] scores 12
FoursAny combinationSum of dice with the number 4[4-4-5-5-5] scores 8
FivesAny combinationSum of dice with the number 5[1-1-2-2-5] scores 5
SixesAny combinationSum of dice with the number 6[2-3-6-6-6] scores 18
Three Of A KindAt least three dice the sameSum of all dice[2-3-4-4-4] scores 17
Four Of A KindAt least four dice the sameSum of all dice[4-5-5-5-5] scores 24
Full HouseThree of one number and two of another25[2-2-5-5-5] scores 25
Small StraightFour sequential dice30[1-3-4-5-6] scores 30
Large StraightFive sequential dice40[2-3-4-5-6] scores 40
YahtzeeAll five dice the same50[1-1-1-1-1] scores 50
ChanceAny combinationSum of all dice[1-1-3-3-5] scores 13

In this challenge, given a set of five dice values, you have to output the score that each category would give (in the order of the previous table).

Formal Inputs & Outputs

Input description

A set of 5 unsorted integers, between 1 and 6.

Output description

A set of 13 integer values that correspond to the scores for each scorecard category, in the order of the previous table.

Examples

yahtzee([1,1,1,1,1]) => [5,  0,  0,  0,   0,  0,   5,  5,   0,   0,  0,  50,   5]
yahtzee([3,5,2,4,5]) => [0,  2,  3,  4,  10,  0,   0,  0,   0,  30,  0,   0,  19]
yahtzee([2,5,2,2,5]) => [0,  6,  0,  0,  10,  0,  16,  0,  25,   0,  0,   0,  16]
yahtzee([1,2,5,4,1]) => [2,  2,  0,  4,   5,  0,   0,  0,   0,   0,  0,   0,  13]
8 Upvotes

0 comments sorted by