0

I have an interesting problem to solve. Provided a list of players and two cards served to them and the first three community cards, the program should find the next two cards for the community to make a selected player the winner. Number of players can be from 2 to 10.

Example Inputs:

  1. List of players and the two cards served to them
  • John - H2, C8
  • David - Sk, Sq
  • Sean - Ca, D7
  1. First three community cards : St,D2,Cj

Question? What can be the next two cards in community to make David the winner? Answer: Sj & Sa (David's best hand would be St, Sj, Sq, Sk, Sa -> Royal flush)

If I say the winner has to be John, the answer could be : S9, Sq (John's best hand would be C8, S9, St, Cj, Sq -> Straight) If I say the winner has to be Sean, the answer could be : Dq, Dk (Sean's best hand would be St, Cj, Dq, Dk, Ca -> Straight)

What would be a good approach to tackle this problem? The only way I could think of is by taking all 2 card combinations from the deck and evaluate the 7 cards for each player using something like this to find the best hand for each player and find the one in which the specific player wins. But it feels like a very brute-force approach. Any other alternate suggestions from anyone?

  • 5
    Brute force? There are less than `52 * 51= 2601` combination of 2 cards. We can try them all and see. Even if we have several decks with jokers mixed we still have at most `53 * 53 = 2809` combinations to test – Dmitry Bychenko Feb 04 '23 at 10:57
  • How much cards is there? If it's a normal deck, go for brute approach – kosciej16 Feb 04 '23 at 10:57
  • 1
    If you have a problem with the performance of your solution, then please show your solution code and demonstrate how it is slow. – trincot Feb 04 '23 at 10:59
  • +1 to @DmitryBychenko, but assuming a single deck it's even better (45 * 44 assuming seven cards have already been dealt out for a two-player game, and the number of possibilities drops all the way down to 29 * 28 for the ten-player case). If you have a shoe with multiple decks it's 52*52 which is still fine for all practical purposes. – Samwise Feb 04 '23 at 11:00
  • @Samwise or half that, since the order of the last two cards doesn't matter. – Paul Hankin Feb 04 '23 at 11:21

0 Answers0