Skip to content

Instantly share code, notes, and snippets.

@yangchenyun
Created February 28, 2019 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangchenyun/1f5ece4b28af3671572f44a92390fd85 to your computer and use it in GitHub Desktop.
Save yangchenyun/1f5ece4b28af3671572f44a92390fd85 to your computer and use it in GitHub Desktop.
Poker game

Determine Winning Poker Hand

Design a program to determine the winner of a poker game.

The order of a card would be described as "23456789TJQKA", the suit of a card would be described as "HSCD" (Heart, Spade, Club, Diamond). Each card would be presented by two characters, i.e. "9D", "KC" etc.

You would be given a list of hands as a text file, each line represents a player's hand. Your program should output the winning hand (or hands if they are tied.)

The winning rules for hand rankings could be found at: https://www.cardplayer.com/rules-of-poker/hand-rankings. In the event of a tie: Highest card wins, and if necessary, the second-highest, third-highest, fourth-highest and smallest card can be used to break the tie.

Example

input:

6C 7C 8C 9C TC
9D 9H 9S 9C 7D
TD TC TH 7C 7D

output:
6C 7C 8C 9C TC
input:
TD TC TH 7C 7D
TD TC TH 8C 8D

output:
TD TC TH 8C 8D

Your solution would be evaluated from two perspective, correctness and code design. So try your best to organize the code as if this is the code would be read and modified by multiple people in a team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment