Those URLs are identical.NESICIDE wrote:Like this?clueless wrote: One very memorable assignment was to write a program to solve the "peg solitaire" game using a depth-first recursive solver. For my final
And this?
Close. Ours was a 7x7 grid, with 16 cells completely not usable (2x2 square in each of the four corners), and the center peg already taken. The goal was to end with the final peg in the center.
Code: Select all
. . X X X . .
. . X X X . .
X X X X X X X
X X X O X X X
X X X X X X X
. . X X X . .
. . X X X . .
I redid mine years later in "C" and didn't use recursion. I kept a stack of pegs moved, and just iterated in place. I could find the first solution much faster on a Celeron 400 MHz. I don't recall how much faster. I do remember that I was trying to find a way to eliminate all of the symmetric solutions and find just the unique ones. But since it wasn't an assignment, and by then I was really busy, I kinda gave up on it.
The point of the original assignment was to study a use for recursion, but also (and more important imho) to learn depth-first search strategies.
Later in the same class we did a depth-first "min-max" search to write a simple AI to play some game. I don't recall what. It might have been tic-tac-toe.
OMG- this reminds me. My company interviewed a recent college graduate for an entry-level programming position. His very first interview question was supposed to be an ice-breaker, but also designed to gauge his intelligence. The interviewer (the Senior developer) challenged him to a game of tic-tac-toe. The candidate got to go first. The candidate lost. The interview was terminated right then. He never made it to the really important interview question: "Why was TK-421 not at his post?"