6
1
Challenge:
In the last stage of a two players Texas hold 'em, given a two-card hand and five cards on table, determine your probability to win versus an opponent by the standard ranking of poker hands.
Input:
Seven cards (sdtin or arguments). The first two cards are your hand while the last five are on the table. Each card will be a two letter string of the form RS where R is rank and S is suit. The ranks range from 2-9, T for ten, and J, Q, K, and A for Jack, Queen, King, and Ace respectively. The suits are H, D, C, S for Hearts, Diamonds, Clubs, and Spades respectively.
Output:
The probability to win (stdout or return): from '0.00' to '1.00'.
Input to Output Examples:
AH 7C KH QH JH TH 6C -> 1.00
Explanation: You have a royal flush, 100% winning chances.
9H 7C KH QH JH TH 6C -> 0.96
Explanation: You have a straight flush, your opponent can only win with an AH, 95.6% winning chances.
Rules and Clarifications:
- There are 52 different cards. You can refer to Texas hold 'em to get the idea.
- Your opponent has 2 unknown cards (out of 45 left). That's 990 possibilities with equal probability.
- You are free to decide if Ties count or don't count in the calculation of the probability.
- As this is code golf, the shortest answer wins.
How should a potential tie be handled in the calculation? And given that you're asking about probabilities, it would be clearer if you made explicit your prior that the opponent holds each of the 990 possible pairs with equal probability. – Peter Taylor – 2014-07-09T07:06:14.377
@PeterTaylor I made "ties" free so you can shorten your code appropriately. – Cœur – 2014-07-09T07:15:55.937
@Cœur - I just want to give you a kudos on the challenge... I've spent about 2.5 hours so far trying to solve this. If I do solve it I think I'll need gzip to make it small! ;-) – scunliffe – 2014-07-13T14:31:23.900
@scunliffe I was thinking of simplifying the challenge by only outputting 0 if you have less than 50% chances winning, or 1 if you have more than 50% chances winning, then I realized some people would hardcode the combinations somehow, compacting it with a hash-table maybe. – Cœur – 2014-07-15T12:13:54.583