started at . submit by
I'm all in! that's what she said, you know. let's calculate poker odds. submissions can be written in any language.
you can represent cards in any format. this specification will use the convention of rank followed by suit, both as single letters, 10 represented as T
. (for example, AS
is the ace of spades.)
poker1 has several types of 5-card "hands", which are ranked by how rare they are. you'll need to know about all of these, so quick overview GO! from highest to lowest:
JC TC 9C 8C 7C
.5C 5D 5H 5S 2D
.6S 6H 6D KC KH
.JD 9D 8D 4D 3D
.TD 9S 8H 7D 6C
.QC QS QH 9H 2S
.JH JS 3C 3S 2H
.TS TH 8S 7H 4C
.aces are the rank above kings, unless registering as the rank below 2 would cause a straight to be formed. this means that AS KS QS JS TS
and 5S 4S 3S 2S AS
are both straight flushes.
within a category, hands are ranked by first grouping them by rank, ordering the groups by length then by value, and comparing lexicographically. id est:
8S 8H 8D 2S 2D
ranks higher than 7S 7H 7D KS KD
.suits are not ranked in any way, so 2 hands are able to rank exactly the same. that'll come up later!
now! we are playing texas hold 'em, which means that several players with 2 secret cards each are trying to form the best hand from a mix of their cards and 5 community cards.
for instance, if the community cards are 2D 9S 9C 4H 5C
, and Paul is holding 9H 3D
, he has three of a kind (9S 9C 9H 5C 4H
). Vanessa sitting next to him could have him beat if she holds a straight (like 6D 3C
) or full house (like 9D 5H
). the deck does not have duplicate cards, so she cannot have four of a kind.
not all of the community cards are revealed at once. on the television, the chance of each player winning (given that each player's hand is known) is displayed in real-time as the community cards are revealed. that is our task for today.
let's return to the example before. if the only visible cards are the first 3 community cards ("flop"), 2D 9S 9C
, Paul has 9H 3D
, and Vanessa has 6D 3C
, the chance of Paul being the winner when the next 2 cards are revealed is 98.38%! when the four of hearts is revealed, that chance falls to 90.91%, and when the five of clubs is revealed, it becomes 0.0% (because Vanessa has now won). what a bad beat!
note that tying is not winning. if no cards are revealed, Paul has AC AH
, and Vanessa has AS AD
, the chance of either one winning (due to a flush) is only 2.7%. in most cases, the suits of the cards won't matter, and Paul and Vanessa will tie, sharing the pot.
your challenge, given a list of 2-card hands and face-up community cards (either 0, 3, 4, or 5 of them), is to calculate the odds of each hand winning. you may also accept a list of cards known not to be in the deck (perhaps because a player folded them), but this is not a requirement.
specifically, the rules listed are for "high rules", as we are playing texas hold 'em. some things change under "low rules", where lower hands are considered better.↩
0 entries have been received so far.