### 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.

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

### Contact

 Search DelphiForFun.org only

### Problem Description

Required: A program which will generate and print the "truth-table" grids which accompany most puzzles in Logic Puzzle books and magazines.

### Background & Techniques

The generated grid actually a set of sub-grids where the cells allow entry of match/no-match values each item of each category with each item of each other category.  So  if two guys are dating two girls, then clues like "Bob's date is Blonde." and "Betty is a Brunette." are enough to let us solve the puzzle.   (I use the letters "T" and "F" for True and False).  When the puzzle is solved, each column and row of each sub-grid will have exactly one "T"

 1. Generated grid 2. "Clues"  applied 3, Each sub-grid row & column must have one "T", rest are "F".  4. The "True" Blonde column and row intersect at John & Betty.  "True" Brunette column and row intersect at Bob & Jane.  Solved!

Printing the grids might be useful if you don't want to spoil the fun for someone else by writing in your magazine.  Also,  "Geo-Cachers" frequently get logic problems without  the grid  being provided  and it was one of those guys that requested this program.

Grid values may be saved and reloaded later.  Multiple copies of the grid (up to 4) may be printed on a page.

### Programmer's Notes:

Technical issues addressed in this program include:

 Vertical printing of column headers.  See Row=0 processing in StringGrid1DrawCell method. Custom drawing of the cells to identify sub-grids with heavy boundaries.  See DrawEdge function called within StringGrid1DrawCell when drawing interior cells. Automatic  scaling of grid size based on number of categories and items.  Text font size can vary from 12 down to 8.  Default cell sizes can range from  are 36 pixels down to height of text if font size is 8. A Modified boolean field flags changed case parameters and function CheckModified givies user a chance to save current before continuing.  If Modified is true, CheckModified ask if user wnat to save before continuing.  "Yes" response call SaveBtnClick method.   "Yes" or "No" response reset the modified flag to false and returns True to the caller.  "Cancel" response leaves Modified set to True and returns False to the caller. Using our PrintGrid unit to print 1, 2, or 4 copies per page provided a couple of enjoyable hours and a  dozen or waste sheets of paper with failed results.

If you dig into the code, be aware that the Categories and Items described here are referred to as Variables and Values within the code.  The Category/Item nomenclature seems to better convey the  meaning of those field for non-math majors.

Finally, the program uses the AdjustGridSize procedure from in our DFFUtils unit in the DFFLibV14 zip file available for download here.   If you haven't already done so, you will need to  download the library file before recompiling this program