Ranking a Poker hand (2) X46837


Statement
 

pdf   zip   main.py

html

The following are some of the possible hands in Poker, in increasing order of value:

  • One pair: Two cards with the same rank.
  • Two pair: Two pairs of cards with the same rank.
  • Three of a kind: Three cards with the same rank.
  • Straight: Five cards with ranks in sequence (aces can be high or low, so Ace-2-3-4-5 is a straight and so is 10-Jack-Queen-King-Ace, but Queen-King-Ace-2-3 is not.)
  • Flush: Five cards with the same suit.
  • Full house: Three cards with one rank, two cards with another.
  • Four of a kind: Four cards with the same rank.
  • Straight flush: Five cards with ranks in sequence (as defined above) and with the same suit.

Using the Card, Deck, Hand, PokerDeck, and PokerHand class definitions, write a PokerHand method named classify that figures out the highest-value classification for a Poker hand and sets the label attribute accordingly.

Your code should work correctly for hands that contain 5 cards.

Input

The input consist of two non-negative integers, the number of hands and the number of cards per hand, followed by a shuffled deck of cards.

Output

Print the cards in each hand followed by a blank line, and a line with the classification of the hand, followed by a blank line.

Precondition

The number of cards in the shuffled deck is not less than the number of hands times the number of cards per hand.

Public test cases
  • Input

    9
    5
    
    5 of Diamonds
    6 of Diamonds
    7 of Diamonds
    8 of Diamonds
    9 of Diamonds
    
    9 of Spades
    Ace of Diamonds
    Ace of Spades
    Ace of Hearts
    Ace of Clubs
    
    Jack of Diamonds
    Jack of Clubs
    Queen of Diamonds
    Queen of Spades
    Queen of Hearts
    
    3 of Hearts
    6 of Hearts
    9 of Hearts
    Jack of Hearts
    Ace of Hearts
    
    5 of Spades
    6 of Diamonds
    7 of Spades
    8 of Diamonds
    9 of Clubs
    
    2 of Diamonds
    2 of Spades
    2 of Hearts
    Queen of Clubs
    5 of Diamonds
    
    9 of Diamonds
    King of Spades
    King of Hearts
    Ace of Clubs
    Ace of Hearts
    
    Ace of Spades
    Ace of Diamonds
    8 of Clubs
    5 of Spades
    4 of Hearts
    
    Ace of Spades
    Queen of Diamonds
    Jack of Clubs
    6 of Diamonds
    5 of Spades
    

    Output

    5 of Spades
    6 of Diamonds
    Jack of Clubs
    Queen of Diamonds
    Ace of Spades
    
    None
    
    4 of Hearts
    5 of Spades
    8 of Clubs
    Ace of Diamonds
    Ace of Spades
    
    One pair
    
    Ace of Hearts
    Ace of Clubs
    King of Hearts
    King of Spades
    9 of Diamonds
    
    Two pair
    
    5 of Diamonds
    Queen of Clubs
    2 of Hearts
    2 of Spades
    2 of Diamonds
    
    Three of a kind
    
    9 of Clubs
    8 of Diamonds
    7 of Spades
    6 of Diamonds
    5 of Spades
    
    Straight
    
    Ace of Hearts
    Jack of Hearts
    9 of Hearts
    6 of Hearts
    3 of Hearts
    
    Flush
    
    Queen of Hearts
    Queen of Spades
    Queen of Diamonds
    Jack of Clubs
    Jack of Diamonds
    
    Full house
    
    Ace of Clubs
    Ace of Hearts
    Ace of Spades
    Ace of Diamonds
    9 of Spades
    
    Four of a kind
    
    9 of Diamonds
    8 of Diamonds
    7 of Diamonds
    6 of Diamonds
    5 of Diamonds
    
    Straight flush
    
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Official solutions
    Python
    User solutions
    Python