[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

Problem Description

Revolve each column of letters up or down to form a common English word reading across each row. When a column revolves, all the letters move up or down in order. If revolving up, the letter at the top of a column wraps around to the bottom. If revolving down, then bottom letter wraps around to the top. Deciding how far to revolve in each  column is up to you.
 

Background & Techniques

This program is based on the MENSA Calendar Puzzle for June 16, 2016.  It implements user play by  revolving letter columns based on user clicks.  There is also a program "Search" button which finds the solution by creating  all rotations of the letter columns and checking each row to see if four words were formed

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:

This should have been an easy program to write, but like many things these days, it took longer than expected.  That's one of the downsides of being a certified optimist I guess.  The program  has about 350 lines of user written code but 150 lines of that are  commented out as a failed initial attempt to solve with recursion.  Actually the code did find the solution, but I didn't like that it did not check all possible letter arrangements and it was not obvious how to fix it.   The replacement "SearchBtnClick" procedure is half the size of the original and does generate all letter rotations.    The trick was to generate "keys" of column rotation lengths for all columns after the first.  

Since there are 4 letters to be rotated and in each column and 4 columns to rotate, there are 44 ( =256) arrangements to check.    If we convert each of the numbers from 0 to 255 to 4 digit base 4 numbers, we get numbers {Keys) from 0000 to 3333 representing all possible ways to rotate the 4 columns (revolve each column up by the number of positions indicated by the number for that column).  The program generalizes and does the calculations based on "RowCount" and "ColumnCount-1" (since first column is fixed).     Once these keys are generated there is one tricky statement to actually rotate letters in all rows for a particular column up by "Start" rpositions..  Here is  the result of a couple of hours of fun:  "For r:=0 to rowcount-1 do rotated[r,c+1]:=toRotate[(r+start) mod rowcount,c+1];"    Works like magic!

"UDict", our dictionary unit is used to check each set of words and, sure enough, Key #153 (2121 base 4 , columns 2,3,4, and 5 revolved up by 2, 1, 2, 1 positions respectively) , produces the solution.   There's a "Debug" check box which displays all generated keys and rotated lines.   All in all, a good bit of mental exercise for the aging brain cells J.

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source  (Note: the DFFUtils, UDict, and Mathslib units  reside in our library zip file of commonly used units.  Library file DFFVLIB13 or later is required to recompile this program )
bulletDownload current library file (DFFLibV15)  to recompile the program.

 

Suggestions for Further Explorations

.Only  a single puzzle is currently implemented, but code was written to allow for additional word lengths and  word counts in the future.
   It would be easy to generate additional puzzles by random selecting words of the required length from our 63,000 word dictionary and then rotating letter columns by a random amount. 
 
   
   

 

Original:  June 27, 2016

Modified:  May 15, 2018

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.