Introduction
Big 2 is a card game popular in East Asia and South East Asia, in which 4 players are dealt 13 cards each (ie, an equal division of a standard deck without jokers). The goal is to empty your hand before any of the other players. Players take turns playing combinations of a Big 2 subset of standard poker hands until their hands are empty. When cards are played, they are considered to be in a discard pile and cannot be reused.
The challenge here is to determine the fewest number of poker hands needed to completely empty a starting hand assuming that there are no other players. In other words, given 13 cards, produce a list of the poker hands that would empty your hand the fastest (ie, the fewest number of 'turns').
Challenge
Given a list of 13 cards of the format <rank><suit>
, produce a delimited combination of Big 2 poker hands that would allow the player to empty their hands as fast as possible. Assume that the given hand can be realistically produced from a single deck of cards (ie, you won't receive 10 aces in your hand).
Inputs
- An unsorted list of 13 cards, meaning that the ranks and suits are not in any patterned/sorted order
- The ranks can be any of
A,2,3,4,5,6,7,8,9,0,J,Q,K
, where '0' is a 10. You may use rank10
in your program if that suits you better. - The suits can be any of
D,C,H,S
, which correspond to diamonds, clubs, hearts, and spades, respectively. - Sample cards would be
AD
for ace of diamonds, or0H
for 10 of hearts.
- The ranks can be any of
- For this example, the inputs are separated by commas, but you can delimit the string however you like, or even use an entirely different representation of a deck of cards that suits your fancy
Outputs
A list (or some delimited string) of cards that indicate play order of your cards. For example the following output formats are valid:
2H, 3D, 4H, 5C, 6S 7S, 7D, 7H 0D, JD, QD, KD, AH
or
[[2H, 3D, 4H, 5C, 6S], [7S, 7D, 7H], [0D, JD, QD, KD, AH]]
or
2H3D4H5C6S, 7S7D7H, 0DJDQDKDAH
or anything else that can delineate hand combinations (aka convenient inputs and outputs)
All three sample outputs indicate that 13 cards were played in the following order: a straight from 2-6, a triplet of 7s, and then a straight from 10-A
- When outputting a 5 card combination, such as for straights or full houses, the cards' ranks/suits do not have to be sorted or grouped in any way - they're mostly shown here for legibility. For example, the straight
2S3S4S5S6S
is equivalent to6S4S2S5S3S
. (23456 == 64253
) - The actual order of moves does not matter as cards cannot be reused anyways
Big 2 Poker Hands
In Big 2, the following poker hands are legal:
- A single card
- A pair of cards, meaning two cards of the same rank regardless of suit
- A triplet of cards, meaning three cards of the same rank regardless of suit
- A straight, a 5 card combination of consecutive ranks regardless of suit.
- Straights cannot start from a jack, queen, or king (ie, the straights of ranks (regardless of suit)
JQKA2
,QKA23
, andKA234
are invalid) - Straights can start from any other rank
- Aces can either be the high card or the low card in a straight, but it cannot appear in the middle of a straight. Namely, the only 2 valid straights that include an ace are
0JQKA
andA2345
.
- Straights cannot start from a jack, queen, or king (ie, the straights of ranks (regardless of suit)
- A full house, a 5 card combination made of three cards of the same rank, and 2 cards of the same, but different rank.
- For example,
000QQ
is a full house with triplet 10s and a pair of queens, but the combination000KQ
is invalid because a pair is needed to complete the triplet
- For example,
- A quad, a 5 card combination made of four cards of the same rank, plus any card of a different rank
- A flush, a 5 card combination of 5 cards of the same suit regardless of rank
- And just for completion's sake: a straight flush, a 5 card combination where the 5 cards are a straight in terms of ranks but also share the same suit.
- Note the straight flush can be computed from either the definition of a straight or a flush, meaning its own distinct definition here isn't necessary for the completion of this challenge.
Tests
Input: AS,4H,6D,8C,7C,3S,5H,8D,4C,2S,0C,AD,AH
Sample output: ASAHAD8D8C, 2S3S4H5H6D, 4C, 7C, 0C
OR 7C, 2S6D3S5H4H, 0C, 4C, 8C8DASAHAD
Explanation: Given the above input, it's possible to generate 2 distinct 5-card combination poker hands. After we play those 2 hands, we only have 3 remaining singles. Thus, the minimum amount of hands we must play is 5. Again, the output card hand combinations do not have to be sorted or played in this specific order (or even in this format) - just leaving it here for legibility.
Input: 2D,0H,5S,0S,4H,AS,4C,6C,6H,KC,8H,5H,8S
Sample output: 5S5H, 4H4C, 0S0H, 6C6H, 8H8S, KC, AS, 2D
Explanation: In this case, it is faster to output 5 pairs instead of a flush (of 5H4H0H6H8H
) because the flush would create 5 dangling single cards that must be played one at a time. Playing the flush would yield 9 turns (1 for flush + 5 singles created from flush + 3 standalone singles), whereas the pair method would require 8 turns (5 turns for 5 pairs, 3 for the leftover singles)
Input: 4D,4S,4H,4C,5H,5D,5C,5S,9S,9D,9H,9C,AD
Sample output: 4D4S4H4CAD, 5D5H5C5S9S, 9D9H9C
Explanation: Outputting quads using the dangling AD
is more efficient than picking the quad's last card from another quad because we can finish off with a triplet.
Rules
- Standard loopholes are forbidden
- Convenient inputs and outputs are allowed
- This is codegolf, so shortest code in bytes wins
2D,7D,8S,AS,2C,9D,5D,2S,AC,0D,8C,8H,5H
: flush, full house, pair, single;5D,2H,4S,QH,9S,2D,9C,JH,0S,AC,KS,JS,3S
: special straight A2345, straight 9 to K (the ace must not be used in that one), 3 singles \$\endgroup\$