A higher resolution is required to access the IDE
- 86
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
You must determine the winner of a hand in Texas Holdem Poker. Output the winning player, their hand type and the five winning card values.CARDS
A card is represented by two characters, one for the value and one for the suit.
• values (descending order):
• suits (no order):
HANDS
A player's hand is the best 5 card-card combination from the 7 card combination of their own 2 hole cards with the 5 community cards. A hand is one of the following types, in descending order of value:
•
•
•
•
•
•
•
•
•
* = A kicker is a leftover card which does not contribute to determining the type of a hand, but is used to break ties. The highest kicker is considered first, then the next, and so on. Only if none of the kickers are larger might a hand be considered a
Note that there's no need to implement a special case for a royal flush.
DETERMINING WINNING HANDS
A higher HandType beats all lower hand types. If the HandType is the same:
• Place cards in the order given below
• Iterate each card in turn, e.g. 1st card Player 1 vs 1st card player 2
• If one value is higher then that player is the winner, else continue to the next card
• If no such win is found, the hand is a
ORDERING CARDS
Cards are ordered by descending non-kicker values, followed by descending kicker values. In case of a
WORKED EXAMPLE
Line 1 : TC JC
Line 2 : AD 4S
Line 3 : 2H 7H TH QS KC
Player 1's 7-card hand:
Player 2's 7-card hand:
Player 1's best 5-card hand is a
Player 2's best 5-card hand is a
A
1 PAIR TTKQJ
Input
Line 1 : holeCardsPlayer1, the 2 hole cards for Player 1, separated by a space.
Line 2 : holeCardsPlayer2, the 2 hole cards for Player 2, separated by a space.
Line 3 : communityCards, the 5 cards on the board, separated by a space.
Line 2 : holeCardsPlayer2, the 2 hole cards for Player 2, separated by a space.
Line 3 : communityCards, the 5 cards on the board, separated by a space.
Output
If there's a winner, the output is WinningPlayerId HandType OrderedFiveCardHand, space-separated. If not, the output is simply DRAW .
WinningPlayerId is1 or 2 .
HandType is as specified above.
OrderedFiveCardHand is the winning 5 cards combination's values, in the order specified above.
WinningPlayerId is
HandType is as specified above.
OrderedFiveCardHand is the winning 5 cards combination's values, in the order specified above.
Constraints
All deals are valid. (all cards exist, no duplicate cards are dealt)
Example
Input
8D 7C 7D 6C KS 9D 5C 3S 2D
Output
1 HIGH_CARD K9875
A higher resolution is required to access the IDE