Your friend invited you to a high-stakes poker game at the last minute and, as a computer scientist, you've decided to use your skills to gain an edge on the game. Your task will be, given 2 cards
(your hand) and 0, 3, 4 or 5 cards
(the dealt cards), you must decide what the best possible hand you can get will be. If all 7 cards are given as arguments, the answer is pretty clear. If given less, the problem becomes more complex. However, this isn't quite enough to give you the edge you're looking for, you must also calculate the best possible hand from the remaining cards to understand what your opponents could have as well.
Hold'em Refresher
If you don't know about hold'em, each player in the game starts with 2 cards as their 'hand'. Over the course of 3 'turns', additional cards are revealed to be shared between all players. The first turn, 3 cards are revealed. The second, 1 more, and the third time a final card is revealed. The two cards given first represent your hand, while the latter represents 0, 3, 4, or 5 cards given by the successive turns.
Possible Numbers:
[2,3,4,5,6,7,8,9,T(10),J,Q,K,A]
Possible Suits:
[S,C,H,D]
Full Deck:
[2S,3S,4S,5S,6S,7S,8S,9S,TS,JS,QS,KS,AS, # Spades.
2C,3C,4C,5C,6C,7C,8C,9C,TC,JC,QC,KC,AC, # Clubs.
2H,3H,4H,5H,6H,7H,8H,9H,TH,JH,QH,KH,AH, # Hearts.
2D,3D,4D,5D,6D,7D,8D,9D,TD,JD,QD,KD,AD] # Diamonds.
Hand Rankings:
1:Royal Flush (A-K-Q-J-10, all from the same suit).
2:Straight Flush (Sequential cards, all from the same suit).
3:Four-of-a-Kind (Self explanatory).
4:Full House (3-of-a-kind and a 2-of-a-kind).
5:Flush (All cards are from the same suit).
6:Straight (Sequential Cards, any suits).
7:3-of-a-Kind (Self explanatory).
8:2-Pair (Double 2-of-a-Kind).
9:Pair (2-of-a-Kind).
10:High Card (You have absolutely nothing except a single card).
Lets take an example or two and walk through them:
The simple example:
[AS, AC],[AH,AD,9S,9C,9H]
-> 3
(Four-of-a-Kind), 3
(Four-of-a-Kind)
The best possible hand you'll have in this setup is the four of a kind hand. The best possible hand your opponents could have is also a 4-of-a-Kind, as you cannot have a KQJ10 in their 2-card hands.
[5C,2C],[6C,4C,JH,JD]
-> 2
(Straight Flush), 3
(4-of-a-Kind)
You're at risk for a straight flush, but because you have the 2/5C in your hand, nobody else is due to you holding both middle cards. The best they can hope for is having 2 pocket Jacks and getting a Jack on the flop.
[JS,JC],[]
-> 1
(Royal Flush), 1
(Royal Flush)
No information you can use against them has been given, all you can tell at the moment is that they can only have a royal flush in diamonds/hearts, but it's just as possible that you get the royal flush as they do. In fact, all inputs where the flop has yet to happen should result in a 1-1 answer.
[2C,4S],[3C,7S,9D,AH,JD]
-> 10
(High Card), 7
(3-of-a-Kind)
This is an example of where you're absolutely screwed, and there's no possibility of a straight or a flush given the river. Meaning the best hand here is pocket aces resulting in a 3-of-a-Kind.
I/O Requirements
- Input must be separated between what is in your hand and what is public knowledge; it'll likely be easier this way regardless of implementation.
- Cards can be tuples or strings, up to you.
- The Hand and the Playing Field can be arrays or delimited strings.
- Output must be two indexes from the list of hands I've provided (E.G. [2,1]).
- It may be returned as part of a function, printed to console or output in a suitable manner.
- There must be two distinct values, one for your best hand, another for the best possible.
- 10 may be represented as a
T
or as10
, whichever makes sense for you. - Standard loopholes are disallowed.
Winning Criteria
- This is code-golf, lowest byte-count with a tie-breaker of post date.
A
and1
in the possible allowed cards? Also I don't think there is really a compelling reason to require the face abbreviations over numeric values like11
. \$\endgroup\$A
and a1
. Everything else looks good. \$\endgroup\$