some brain exercise for the kiddies.
the combination that will open the safe by clicking the buttons in
the proper sequence. The final button is marked "Last",
but it's up to you to discover the starting point. Each button
except the Last has instructions for finding the next, the number of
squares to move and a abbreviation of the direction to move (Up,
Down, Left, or Right)..
Background & Techniques
This is another puzzle adapted from a type in the Mensa Number Puzzles
Book (Harold Gale, Carlton Books). The computer version generates random "combinations"
and allows users to control problem size from 2X2 to
There are at least four approaches to solving this
- Click on a random square and follow the
movement directions from there to Last. If you do not pass
through all of the buttons, the true starting point will be one of the
- The starting button is the only one that
cannot be reached from another button. Examining each button
in turn will eventually turn up the proper one. The
"link-from" button, if it exists, will be one of the buttons
in the sharing the same row or column as the button being
- You can start at Last and work backwards
to the starting button.
- Finally, you can click the Auto-Unlock
button. The program uses the "search backward" technique to
find and display the correct. path.
Non-programmers are welcome to read-on but may want to jump the the
bottom of the page now to download the executable version of the program.
Notes for programmers
A two dimensional dynamic array of strings, Grid, is used to
hold the text to be displayed on the board.
Procedure MakeBtnClick generates a valid set of values by trial and
error. It calls MakeValidMove to define the next
cell. MakeValidMove tries 1000 times generating random
directions & distances and returns false if no valid move can be
Dynamic array Path contains the cells coordinates ofcells in the
current path, whether a full path generated by the computer or a partial
path generated by the user. Procedure DrawBoard handles
drawing the board with current Grid values. Procedure DrawPath
highlights the cells in the path, placing small sequence numbers in the
upper left corner of selected cells and coloring them green for the first
cell, red for the last cell and silver for the intermediate cells. Drawpath
takes a Sleepval parameter used to introduce a 1/2 second delay for
each cell drawn when displaying the computer solution.
TImage, Image1, contains the board image. A Mousedown
exit for Image1 is used to handle user clicks, adding valid next
cell clicks to the path and beeping for invalid clicks..
Function GetNext is passed coordinates of a cell and returns the
coordinates of the next cell. It is used to check validity of user
clicks. It is also used by function GetPrev which
finds the previous cell by passing cells in order to GetNext until
the return value is equal to GetPrev's
input. GetPrev is used by the
computer solution search procedure, UnlockBtnClick, which starts at
cell LAST and builds the solution path by searching backwards using
calls to GetPrev.
Enough of the talk - let's go!
Running/Exploring the Program
Suggestions for Further Explorations
"expert" level of play could more closely emulate a
real combination lock by forcing a complete restart after any wrong
could be added, scores based either on error counts, time to
solve, or both.
original version had a search backward mode allowing uses to find
the solution by searching backward from last call to
more elaborate reward for correct solution could be added. I
have a Rewards unit floating around somewhere, but was too
lazy to implement it here.
|Original Date: June 26, 2002
Modified: February 18, 2016