[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Problem Description
Background & TechniquesThis puzzle is from the May 2, 2018 MENSA Puzzle Calendar. It is a hard puzzle because there is only one correct way to place the letters of the of the 40,000+ ways to do so. The program allows manual solving by users as well as a "Show me" button to trigger a program search. A hint for manual solving: start with trial locations for I, G, B, and H which satisfy rules 3 and 4 since there relatively few valid locations for these letters. The program search will search all possible letter arrangements, but gets these 4 letters placed first because checking rules 1 and 2 require searching the entire grid; a much slower process.. Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now. Programmer's Notes:The program uses our "UCombos" unit to generate all possible ways to permute 8 items. Each call to Combos.Getnext returns a permutation of the integers 1 to 8 in th Selected array. Each position in the array represents a cell in the grid working left to right and top to bottom starting with the middle cell of the top row. Each value 1 through 8 stands for a letter B through I. Most tests can be done without actually filling the grid. For example selected[3],selected[4] and selected[5] represent the middle grid row, so to satisfy Rule 3, one of those three values must be an 8 (I) and none of them can be a 6 (G). If either of those conditions is not met, we can stop checking and go on the next permutation. Similar testing for B and H ensure that they are in corners. The Rule 1 single vowel test requires a scan of each row and column the grid which I do by passing 2 (for row and column 1) or 3(other rows and columns) Selected array locations to a CountVowels function which returns the number of vowels found. Finally, the "no consecutive" rule require checking each row and column by calling a Consecutives function which compares values in the selected passed cell numbers looking for numbers which differ by 1 indicating that they are adjacent in the alphabet. All of the testing is done in an AllRulesOK function called for each permutation in the program search and also called for each final (8th) grid character entered by the user. When users enter a character that duplicates an existing one, the program automatically removes the existing character before adding the new one.
Running/Exploring the Program
Suggestions for Further Explorations
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |