# Thread: Poker game good algorithm for solving ties between two pairs Thanks: 0 Likes: 0

1. ## Poker game good algorithm for solving ties between two pairs

This is the Poker problem in one of previous year's final. See question here
I attempted most questions in the problem and have attached my worksheets, and here's my question:
Does anyone have any good idea how to best solve ties between two pairs?
8C 8D 7S 5S 5C
9C 8S 8H 5H 5D

Here's my idea:
step 1: rank the five cards (solved in part 1)
step 2: Since there're two pairs in five cards, there must be a pair in the first three cards, and another pair in the last three cards. We can use the Mode function to find the two pairs
step 3: if both pairs are equal, we can just do a high card rank for all the cards in order to break ties.

What do you think is the best way to do it?

2. ## Re: Poker game good algorithm for solving ties between two pairs

Hi sshoul14,
Was puzzling over this one for some time. You can't just find the high card if both pairs are equal because the high card could be part of one of the pairs. You have to find the one that isn't a pair or the one that occurs least frequently and rank them. I assume during your sorting process you separated the numbers and suits. For me, this was in row 9. I found this on another site but it worked great to find the single card for player 1.

=INDEX(\$D\$9:\$H\$9, MATCH(MIN(INDEX(COUNTIF(\$D\$9:\$H\$9,\$D\$9:\$H\$9),0)), INDEX(COUNTIF(\$D\$9:\$H\$9,\$D\$9:\$H\$9), 0),0))

Use the same format for player 2 and then rank them. I hate really long formulas so I made a little table for high pair/low pair/single for each player using Mode as you suggested in step 2 and the above for the single.
Once I found that line it was easy.

3. ## Re: Poker game good algorithm for solving ties between two pairs

Originally Posted by edopts
You can't just find the high card if both pairs are equal because the high card could be part of one of the pairs. You have to find the one that isn't a pair or the one that occurs least frequently and rank them.
Welcome to the MrExcel board!

The blue part is right. The red part might work but I don't agree with the underlined part.

I'm guessing to some extent but I don't think sshou14 was suggesting "just find the high card". Considering the particular example shown and given it is already established that there are two equal pairs then I think the underlined part below meant:

Hand1: 8+8+7+5+5=33
Hand2: 9+8+8+5+5=35
Hand2 wins

Originally Posted by sshou14
Does anyone have any good idea how to best solve ties between two pairs?
8C 8D 7S 5S 5C
9C 8S 8H 5H 5D

Here's my idea:
step 1: rank the five cards (solved in part 1)
step 2: Since there're two pairs in five cards, there must be a pair in the first three cards, and another pair in the last three cards. We can use the Mode function to find the two pairs
step 3: if both pairs are equal, we can just do a high card rank for all the cards in order to break ties.

4. ## Re: Poker game good algorithm for solving ties between two pairs

Peter,
Well that is much less complicated and works equally well. Just out of curiosity though, I think my method might be necessary to determine tie breaks for a full house since the total could be vastly different. The problem assigns a value of 14 to an ace. Therefore, a full house of AA222 is beaten by 44333 but the first hand would total 34 while the second hand only totals 17.
I believe I have solved the problem, so I am just interested if you would have a different method of solving that tie break.
Thanks,
Ed

5. ## Re: Poker game good algorithm for solving ties between two pairs

Originally Posted by edopts
I think my method might be necessary to determine tie breaks for a full house ..
As far as my knowledge of poker hands goes it is not possible to get a tie with two full house hands so a tie breaker would be unnecessary.

6. ## Re: Poker game good algorithm for solving ties between two pairs

Ah, true. its part of the steps of the original problem.
First you identify each player's hand. If both players have the same hand, (a full house, straight, 2 pair, etc), then you have to determine which is better. My use of the words "tie breaks" was the verbiage used in the problem and not necessarily in the context of poker.

7. ## Re: Poker game good algorithm for solving ties between two pairs

Hi edopts, Peter,

Actually, the blue part highlighted is incorrect, in the context that shhou14 was using it, I think. The high card rule should work its way down both hands, see that both high cards tie, and move to the next highest card. This is required to solve one of the other parts of the problem, to break ties when there are no hand combinations available.

So if we had two hands with the following cards, we should have the following results:

H1 : 8, 8, 7, 5, 5
H2 : 8, 8, 5, 5, 4
Win: T, T, 1, -, -

... thus identifying that Hand 1 is the winner.

sshou14, your approach is basically the way that we solved the 'two pairs' problem in the official Corality Worked Solution, except we took a different approach to determining the value of the two pairs, rather than using the MODE function as you have.

8. ## Re: Poker game good algorithm for solving ties between two pairs

In the case there are 2 pairs, after solving step 1, the higher pair is the 2nd card and the lower pair is the 4th card.
If both pairs are equal, we can just do a high card rank for all the cards in order to break ties.

For ranking high card, since all the card are ranked then you can find the winner by comparing the two sums: Sum1 of player1 = Card1*10^4 + Card2*10^3 +Card3*10^2 +Card4*10 + Card5. Similar for Player2.
If sum1 = sum2 then it's a tie, if sum1 > sum 2 then player 1 wins.

9. ## Re: Poker game good algorithm for solving ties between two pairs

I also attempted questions in the problem and have attached here

## User Tag List

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•