Note this is a simpler version of Contest 8 which had no entries!
You are provided with a text file holding 1000 x 7 sets of cards (in no order). Your application must identify the best poker hand made up of 5 cards from the 7 provided. These cards are - or space separated and look like this: 3S-9D 5S-6D-TH-2S-KC. The first letter of each pair is the value which is one of 2,3,4,5,6,7,8,9,T,J,Q,K, A. The second letter of each pair are suits, and are H,C,D and S standing for hearts, clubs, diamonds and spades.
You should value the hands according to the rules of poker which you will find here.
Poker Hands From Best to Worst
- SF Straight Flush - A straight flush is five cards in sequence, all of the same suit,
- FK Four of a Kind - Four cards, all the same value
- FH Full House - Three carsd of one value, and two of another
- FL Flush - Five cards all the same suit
- ST Straight - Five cards in the same sequence
- TK Three of a Kind- Three cards of the same value
- TP Two Pairs - Two sets of two paired cards
- OP One Pair - Two paired cards- ie the same value
- HC - High Card - Highest value Card. Ace is highest, 2 is lowest
You should calculate which hand is best and use the two letter code in the output file.
Input Files
There is one file, located in the same folders as your exe called cards.txt.
- Download cards.txt. This is a text file holding 1000 sets of 7 cards.
The Output
Output a file output.txt in the same location as your exe. The first line should have the average time of a run. A run is all 1000 Hands. If your code is lightning fast redo the calculation so it takes a few seconds.
"Average time = 0.87 sec"
The rest of the file should be 1000 lines containing the five cards you kept out of seven cards and the two letter code from the table above. In this example I've dropped the 2S and 3S.
9D-5S-6D-TH-KC HC
In this example no pairs or other hands were found so it's a High Card (HC).
Timing Code
Please time from the start of the run, after reading in the input file until just before the output file is opened for writing. This code below will do high speed timing.
Final Results
Congrats to Jon Drane's stunningly fast C code which saw off very strong contenders. Thanks to all who entered.
- Jon Drane - C 0.000142696
- Ivan Dimov - C++ 0.000227
- James Borden - C# 0.0002587186 James Borden's website
- Pedro Graca - C 0.000299
- Raymond Martineau - C++ 0.004316
- Năstasie Octavian - C# 0.0049065
- Scott Hein - C# 0.0087818
- Jeffrey Sander - C# 0.0327426
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 Contest 40 email address with the subject line Programming Contest 40.
It must compile with Open Watcom, Microsoft Visual C++ 2008/2010 Express Edition/Microsoft Visual Studio 2008/2010 or Borland Turbo C++ Explorer, Microsoft Visual C# 2008/2010 Express Edition or GCC/G++. 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 October 31 2010.
The top ten entries will be listed, judged purely on points. 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.
- An index of Every Past Programming Contest on this site

