Poker Jack Queen King Ace Two

  1. Poker Jack Queen King Ace
  2. Ace King Queen Jack
  3. Poker Straight Jack Queen King Ace Two
  4. Ace King Queen Jack 10
  5. Jack Queen King Ace Two
  6. Jack Queen King 3 Review
  7. Ace King Poker Chips
Ahh, I have gone back and reworked this problem. Thanks Jim for pointing out that there was an error - I accidentally computed it as if the order of the cards being given mattered.

The file, poker.txt, contains one-thousand random hands dealt to two players.Each line of the file contains ten cards (separated by a single space): the first five are Player 1's. Math 221 Counting Worksheet: Poker Hands A standard 52-card deck consists of 13 cards from each of 4 suits (spades, hearts, diamonds, clubs). The 13 cards have value 2 through 10, jack (J), queen (Q), king (K), or ace (A). Each value is a “kind” of card. The jack, queen, and king are called “face cards”. How many 5-card poker hands are there? SOL'N:a)A royal flush is ace, king, queen, jack, and ten of the same suit. If we order the 5-card hand from highest card to lowest, the first card will be an ace.

To compute the number of possible hands, it is simply 52 choose 5, i.e. 2,598,960.
To find the number of hands that contain exactly one pair, we first need a card to pair, i.e. 13 choose 1. Now, we need two of them: 4 choose 2. Next choose three denominations of the remaining 12 options, i.e. 12 choose 3, and for each we need a suit, so 4 choose 1, but three times.
Written in text, this is (13c1)(4c2)(12c3)(4c1)^3 = 1,098,240.
Therefore, the probability is 1,098,240/2,598,960 = 42.26%.
Good call Jim!

Jim S.

I've been playing poker for many years and I can assure you the probability of being dealt a pair is about 40% not 4%
There are about 1,000,000 different hands that contain only pairs and there are about 2,500,000 different 5 card poker hands so 1/2.5=.4
Jim
Simply Scheme:Introducing Computer Science 2/e Copyright (C) 1999 MIT
BrianHarvey
University of California, Berkeley
MatthewWright
University of California, Santa Barbara

Download PDF version
Back to Table of Contents
BACKchapter thread NEXT
MITPress web page for Simply Scheme

The idea of this project is to invent a procedure poker-valuethat works like this:

As you can see, we are representing cards and hands just as in theBridge project, except that poker hands have only fivecards.[1]

Here are the various kinds of poker hands, in decreasing order of value:

Royal flush: ten, jack, queen, king, and ace, all of the same suit
Straight flush: five cards of sequential rank, all of the same suit
Four of a kind: four cards of the same rank

Poker Jack Queen King Ace

Full house: three cards of the same rank, and two of a second rank
Flush: five cards of the same suit, not sequential rank
Straight: five cards of sequential rank, not all of the same suit
Three of a kind: three cards of the same rank, no other matches
Two pair: two pairs of cards, of two different ranks
Pair: two cards of the same rank, no other matches
Nothing: none of the above

An ace can be the lowest card of a straight (ace, 2, 3, 4, 5) orthe highest card of a straight (ten, jack, queen, king, ace), but a straightcan't 'wrap around'; a hand with queen, king, ace, 2, 3 would be worthless(unless it's a flush).

Notice that most of the hand categories are either entirely about the ranksof the cards (pairs, straight, full house, etc.) or entirely about thesuits (flush). It's a good idea to begin your program by separating therank information and the suit information. To check for a straight flush orroyal flush, you'll have to consider both kinds of information.

In what form do you want the suit information? Really, all you need is atrue or false value indicating whether or not the hand is a flush, becausethere aren't any poker categories like 'three of one suit and two ofanother.'

What about ranks? There are two kinds of hand categories involving ranks: the ones about equal ranks (pairs, full house) and the ones about sequentialranks (straight). You might therefore want the rank information in twoforms. A sentence containing all of the ranks in the hand, in sorted order,will make it easier to find a straight. (You still have to be careful aboutaces.)

For the equal-rank categories, what you want is some data structure thatwill let you ask questions like 'are there three cards of the same rankin this hand?' We ended up using a representation like this:

One slightly tricky aspect of this solution is that we spelledout the numbers of cards, one to four, instead of using the moreobvious (1 Q 2 3 2 4). The reason, as you can probably tell just bylooking at the latter version, is that it would lead to confusion betweenthe names of the ranks, most of which are digits, and the numbers ofoccurrences, which are also digits. More specifically, by spelling out thenumbers of occurrences, we can use member? to ask easily if there isa three-of-a-kind rank in the hand.

You may find it easier to begin by writing a version that returns only thename of a category, such as three of a kind, and only after you getthat to work, revise it to give more specific results such as threesixes.

Extra Work for Hotshots

Ace King Queen Jack

In some versions of poker, each player gets seven cards and can choose anyfive of the seven to make a hand. How would it change your program if theargument were a sentence of seven cards? (For example, in five-card pokerthere is only one possible category for a hand, but in seven-card you haveto pick the best category that can be made from your cards.) Fix yourprogram so that it works for both five-card and seven-card hands.

Another possible modification to the program is to allow for playing with'wild' cards. If you play with 'threes wild,' it means that if there isa three in your hand you're allowed to pretend it's whatever card you like.For this modification, your program will require a second argument indicatingwhich cards are wild. (When you play with wild cards, there's thepossibility of having five of a kind. This beats a straight flush.)

Poker Straight Jack Queen King Ace Two

[1] Later on we'll think about seven-card variants of poker.

Ace King Queen Jack 10

Review

Jack Queen King Ace Two

BACKchapter thread NEXT

Jack Queen King 3 Review

Brian Harvey,

Ace King Poker Chips

bh@cs.berkeley.edu