There is a classic triangle version of this, and a larger one and many other shapes on the tables at the Cracker Barrel restaurant.
A good many years ago I wrote a little C++ program to solve the triangle puzzle in general, using an integer to represent the state (bit set for peg present) and logic to represent the connectivity between the holes. Changing that logic can make the puzzle into whatever shape and size we want to solve.
If memory serves, I used an array indexed by this state number to point to another valid state closer to the solution, started with the solution and populated the array working backwards, and then could use the array as a map of what to do in any state and/or say whether it was winnable.
I came across one of those puzzles again, and the use of golf tees reminded me of Perl Golf, too. So I started thinking about solving this puzzle in Perl. C++ was pretty efficient, but could not be reconfigured for the puzzle shape. Perl’s strengths is associations, so a similar approach using hashes or references might be the way to go.
So I propose a challenge: to write a Perl Module to solve this general class of puzzle. An instance of the module is used by a main program to configure the actual puzzle and explore the details such as printing out a list of moves.
The goal isn’t to make it short like in Golf, but to make it clear, maintainable, efficient, and reusable. You don’t have to post a whole solution—just discussing different approaches can be enlightening and interesting.
—John
|
|---|