The game has 81 cards each with four varying characteristics.
- Number of symbols (One, Two or Three- all the same shape)
- Color (One of red, green and purple)
- Shape (One of diamond, squiggle, or oval)
- Shading (Filled in, empty or cross hatched).
The game rules are simple- 12 cards are put down on the table in front of the players and you have to identify a matching set of three before anyone else. The player who spots a set first gets those cards. Then three more cards are put down on the table and it continues until all cards are out and no more sets can be found. The player with the most sets wins.
A matching set is one where the three cards have each of the 4 characteristics all the same or different. For example you can have a set where the shapes and colors are different but the shading and numbers are the same. The picture from Wikipedia shows a set where all 4 characteristics are different.
The ChallengeWrite a program that simulates the Set game. Specifically it
- Generates the 81 cards and holds them in memory.
- Plays 10,000 games of Set.
- Times how long it takes to play the 10,000 games.
ResultsThere were five entrants, 1 in C, 1 in C++ and three C#. The winner was the C++ version.
- Chris Runyan ( C++ ) in 0.155421 seconds
- Andre Prata ( C ) in 0.7865 seconds
- Makis ( C# ) in 0.99106 seconds
- Shashi Sadasivan ( C# ) in 1.98703 seconds
- Robert C. Cartaino ( C# ) in 0.076598 seconds*
* My Apologies to Robert C Cartaino whose code I accidentally modified, leaving it limping along when in fact it was very very fast and should be counted as the winning entry (But as it's unfair to change winners due to my mistake...). I have also uploaded the unmodified code. Chris Runyan deservedly gets the title "Fastest C++ in the west".
RulesThis is for glory only. About.com does not permit prizes to be given.
Please submit your source code and the output file to the email@example.com?subject=Programming Challenge 11 email address with the subject line Programming Challenge 11.
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 April 30 2008.
The top three entries will be listed according to speed with fastest is best. 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.
More Programming Challenges
- Link to Rock, Scissors and Paper Bot Ongoing Programming Challenge - Runs weekly.
- 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 8 - Score Poker Hands - (Finished)
- Link to Programming Challenge 9 - Manage a Data structure - (Finished)
- Link to Programming Challenge 10 - Hide Text (Finished)
- Link to Programming Challenge 12 - Find the Shortest Routes (Ends on May 31