Each card is represented by two characters. The first is the card value and is one of 23456789TJQKA. The 2nd is the suit and is one of HCDS. I.E. Hearts, Clubs, Diamonds and Spades.
Each line is formatted as follows:
1,JS 3D KH 8D 8S, KD 4S, 3S KC, QH 6C, 4H 7C, 2D TS, 5H QS, 7D KS, 5S 6HThe above shows the first line and the last in the file.
...
1000,JH 5H 6C 7S QC, TS 3C, KC 8C, 8S TC, 3H 6D, KD 7C, 2H 9S, AH JC, 2D TH
This file has 1000 lines and is about 77Kb in size. Note that each line was generated from a freshly shuffled pack so there is no correlation or link between lines.
The first five spaces are the hand number 1-1000, then a comma then five cards each separated by a space, then a comma plus space then 8 pairs of cards, with each pair separated by a comma plus a space between each card.
Help With Poker
Wikipedia has the rules of Texas Holdem if you are unfamiliar with them. Also the full list of Poker Hands is here.Scoring a Hand
In Texas Holdem each player's hand is any 5 cards drawn from the two that he/she holds plus the 5 community cards. IE there are 7 cards for each player (5 community + 2 they hold) and you have to score the best 5 card hand from those 7 cards for each player.In the first line the 5 community cards are JS 3D KH 8D 8S. Player 1 has KD 4S so his best hand is two pairs: Kings and 8s. Although player 2 has a King and a 3 the best score is still two pairs the same as player 1. Player 7 also has this, so this hand will be a draw between players 1, 2 and 7. In the 1000th match, player 7 has two jacks so wins.
When you score the match please use the following nine values to represent the winning hand:
- 0 - High Card.
- 1 - Pair.
- 2 - Two Pair.
- 3 - Three of a Kind.
- 4 - Straight.
- 5 - Flush.
- 6 - Full House.
- 7 - Four of a Kind.
- 8 - Straight Flush.
Entering the Challenge
Write an application to read the file. It is 1,000 lines long, with each line terminating in a '\n''\r' sequence, i.e. (0xd, 0xa) which is a Carriage Return and a Linefeed character.Please time how long it took to score the hands as the first line of output before the validation output. I.e. you should time after you have read the 1,000 lines in and before you output the 1,000 lines below.
Your application (GUI or Command line) should then output to a text file 1000 lines with 4 comma separated sets of values. These are
- Hand Number (1-1000)
- Score value 0-8
- Winning Player or Drawn Players (in text form) Player 6 or Players 5+7
- Text of Winning Hand e.g. Full House: Fives and Jacks
Time To Score = 5.56 seconds
1,2,Players 1+2,two pairs:kings and eights.
...
1000,1,Player 7,pair of jacks
Rules
This is for glory only. About.com does not permit prizes to be given.Please submit your source code and the output file to the cplus.guide@about.com?subject=Programming Challenge 8 email address with the subject line Programming Challenge 8.
It must compile with Open Watcom, Microsoft Visual C++ 2005/2008 Express Edition/Microsoft Visual Studio 2003/2005/2008 or Borland Turbo C++ Explorer, Microsoft Visual C# 2005/2008 Express Edition. If it doesn't compile, it can't be run so is automatically disqualified
Please include your name, age (optional), blog/website url (optional) and country. Your email address will not be kept, used or displayed except to acknowledge your challenge entry. You can submit as many entries as you like before the deadline which is January 31 2008.
The ten entries with the highest scores (decided by fastest times for ties) will be listed. A condition of entry is that you allow your source code to be published on this website, with full credits to you as the author.
Have fun!
More Programming Challenges
- Link to Rock, Scissors and Paper Bot Ongoing Programming Challenge - Runs weekly until 2008.
- Link to Programming Challenge 2 - Count the Islands. (Finished)
- Link to Programming Challenge 3 - Manage Elevators. (Finished)
- Link to Programming Challenge 4 - Guess the Mastermind Code - (Finished)
- Link to Programming Challenge 5 - Squeeze words into a crossword grid - (Finished)
- Link to Programming Challenge 6 - Guess the Mastermind Code - (Finished)
- Link to Programming Challenge 7 - Validate Chess Positions - (Finished)
- Link to Programming Challenge 9 - Manage a Data structure - (Finished)
- Link to Programming Challenge 10 - Hide text in the text of a book - (Deadline March 31 2008)


