Ranking a Poker hand (1) X89471


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, and PokerDeck class definitions, write a PokerHand class with methods named has_one_pair, has_two_pair, etc. that return True or False according to whether or not the hand meets the relevant criteria.

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 for each of has_one_pair, has_two_pair, has_three_of_a_kind, has_straight, has_flush, has_full_house, has_four_of_a_kind, and has_straight_flush, 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

    1
    5
    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
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    Ace of Spades
    Ace of Diamonds
    8 of Clubs
    5 of Spades
    4 of Hearts
    

    Output

    4 of Hearts
    5 of Spades
    8 of Clubs
    Ace of Diamonds
    Ace of Spades
    
    One pair: True
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    9 of Diamonds
    King of Spades
    King of Hearts
    Ace of Clubs
    Ace of Hearts
    

    Output

    Ace of Hearts
    Ace of Clubs
    King of Hearts
    King of Spades
    9 of Diamonds
    
    One pair: False
    Two pair: True
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    2 of Diamonds
    2 of Spades
    2 of Hearts
    Queen of Clubs
    5 of Diamonds
    

    Output

    5 of Diamonds
    Queen of Clubs
    2 of Hearts
    2 of Spades
    2 of Diamonds
    
    One pair: False
    Two pair: False
    Three of a kind: True
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    5 of Spades
    6 of Diamonds
    7 of Spades
    8 of Diamonds
    9 of Clubs
    

    Output

    9 of Clubs
    8 of Diamonds
    7 of Spades
    6 of Diamonds
    5 of Spades
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: True
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    3 of Hearts
    6 of Hearts
    9 of Hearts
    Jack of Hearts
    Ace of Hearts
    

    Output

    Ace of Hearts
    Jack of Hearts
    9 of Hearts
    6 of Hearts
    3 of Hearts
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: True
    Full house: False
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    Jack of Diamonds
    Jack of Clubs
    Queen of Diamonds
    Queen of Spades
    Queen of Hearts
    

    Output

    Queen of Hearts
    Queen of Spades
    Queen of Diamonds
    Jack of Clubs
    Jack of Diamonds
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: True
    Four of a kind: False
    Straight flush: False
    
    
  • Input

    1
    5
    9 of Spades
    Ace of Diamonds
    Ace of Spades
    Ace of Hearts
    Ace of Clubs
    

    Output

    Ace of Clubs
    Ace of Hearts
    Ace of Spades
    Ace of Diamonds
    9 of Spades
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: True
    Straight flush: False
    
    
  • Input

    1
    5
    5 of Diamonds
    6 of Diamonds
    7 of Diamonds
    8 of Diamonds
    9 of Diamonds
    

    Output

    9 of Diamonds
    8 of Diamonds
    7 of Diamonds
    6 of Diamonds
    5 of Diamonds
    
    One pair: False
    Two pair: False
    Three of a kind: False
    Straight: False
    Flush: False
    Full house: False
    Four of a kind: False
    Straight flush: True
    
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Official solutions
    Python
    User solutions
    Python