The August 30 edition of the EE Community Newsletter posted a puzzle contest. The newsletter wasn't really clear (sorry editors) on one of the key rules, specifically what language(s) were appropriate for the contest. Clearly though, C was not acceptable as the size of the passed array is indeterminate to a C function. Can you believe it? The foundation language for so many of the so-called "modern" languages isn't allowed to play?
So let them have their silly game. We'll have ours.
I'm proposing that we conduct the same contest but in C. I'll provide the points for the winner(s). Here are the (amended) rules.
1. The object is to solve the "Cracker Barrel Peg Solitaire" game. (This game has been around for a very long time, even before Cracker Barrel started to feature it.) For rules and descriptions see the newsletter. For a picture of the game, see this link:
http://shop.crackerbarrel.com/images/400/606154.jpg2. The number of pegs in the game may/will vary. The base game has 5 rows in a diamond. Our game will have no fewer than 5 rows and may have more. Your code must handle games of arbitrary size.
3. Only C code is acceptable. I will test the entries on my AMD 64-3800 Fedora Core 5 system. Entries will be compiled with gcc using the default options.
4. Entries will not be accepted prior to September 16, 2006 so everyone will have a chance to think about the problem before source code is passed around in this thread. I will ask the mods/page editor(s) to delete responses with source code submitted prior to that date.
5. Entries must be received prior to September 23, 2006. That gives everyone 2 weeks to write their programs.
6. Code rules:
A. Only C code is acceptable. It must compile on the system mentioned above or the program will be rejected.
B. You can have as many arrays, constants, functions, etc. as you want.
C. I will build the main() function used to test the entries.
D. main() will call each solver function repeatedly with a predefined set of "games".
E. The solver function WILL use the standard prototype.
int SolveOnce (int size, int *puzzle); // returns 0 if no solution, 1 if solution found.
F. In the prototypes, size is the number of holes, not the number of rows.
G. puzzle[] contain a 1 where a peg exists, a 0 where the hole is empty.
Note that more than one hole may be empty for any defined game. ;)
H. Your function must be self initializing. It will be called thousands of times to get accurate timing.
I. The array being passed can be considered volatile. Scribble all that you want. :)
Z. Please make it easy on me. Structure your code so that in your submission, main() is the last thing in the source code. This way I can use sed, awk, perl or other scripting tool to simply delete all of the source code starting at main(), append the main() to be used for the test, compile, and execute.
Good Luck, and good coding. :)
Kent