Problem 148894 · hard · Phase 01 Prerequisites & Setup

Joker Dice

conditionals · loops · lists

A dice game rolls five dice. Faces are 1 to 6, and a face of 0 is a joker: each joker may count as any face from 1 to 6 (different jokers may count as different faces). Write best_hand(dice) that returns the name of the best category the roll can make.

Categories from best to worst (a roll belongs to the first one it satisfies):

  1. "five of a kind": all five faces equal.
  2. "large straight": the faces are exactly 1,2,3,4,5 or exactly 2,3,4,5,6 in some order.
  3. "four of a kind": four faces equal.
  4. "full house": three faces equal and the other two equal to each other (but different).
  5. "small straight": four of the faces are 1,2,3,4 or 2,3,4,5 or 3,4,5,6.
  6. "three of a kind": three faces equal.
  7. "two pair": two different faces each appear at least twice.
  8. "pair": some face appears twice.
  9. "nothing".

Examples

Input:  dice = [3, 1, 4, 1, 5]
Output: "pair"

Input:  dice = [2, 6, 0, 4, 5]
Output: "large straight"
Explanation: the joker counts as a 3.

Input:  dice = [6, 6, 1, 1, 0]
Output: "full house"

Constraints

  • len(dice) == 5
  • every value is an integer from 0 to 6

Goals

  • Classify a hand by counting faces
  • Rank overlapping categories with a fixed priority
  • Try every value a wild card could take
Starting Python…