31
8
Poker hands are ranked from best to worst as follows:
- Straight flush - five cards of sequential rank, all of the same suit
- Four of a kind - four cards of the same rank and one card of another rank
- Full house - three cards of one rank and two cards of another rank
- Flush - five cards all of the same suit
- Straight - five cards of sequential rank
- Three of a kind - three cards of the same rank and two cards of two other ranks
- Two pair - two cards of the same rank, two cards of another rank and one card of a third rank
- One pair - two cards of the same rank and three cards of three other ranks
- High card - five cards not all of sequential rank or of the same suit, and none of which are of the same rank
- Rank = The number on the card (A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3, 2). You may choose to use T instead of 10.
- Suit = hearts (h), spades (s), clubs (c) and diamonds (d).
Note that the Ace, A
, can both be the highest and the lowest number (1 or 14).
A card can be identified by two letters As
(Ace of spades), Jc
(Jack of clubs), 7h
(7 of hearts) and so on.
Challenge:
You get four cards from the dealer (four input strings). Find and output the best possible last card you can get.
If there are cards that are equally good then you can choose which to pick.
Input and output formats are optional, but the individual cards must identified as shown above Jc
and 2h
.
Test cases:
Ah Kh Jh 10h
Qh
7d 8h 10c Jd
9d (or 9h, 9c, 9s)
Js 6c 10s 8h
Jc (or Jh, Jd)
Ac 4c 5d 3d
2h (or 2d, 2c, 2s)
5s 9s Js As
Ks
2h 3h 4h 5h
6h
Js Jc Ac Ah
As (or Ad) <- Note that AAAJJ is better than AAJJJ because A is higher than J
10d 9d 5h 9c
9h (or 9s)
Ah Ac Ad As
Ks (or Kd, Kh, Kc)
4d 5h 8c Jd
Jc (or Js, Jh)
This is code golf, so the shortest submission in bytes win.
2Very creative, and great explanation! – Greg Martin – 2016-11-16T19:40:25.900