Mind your P's and Q's

[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

The task here is to divide the displayed grid into two identically 
shaped pieces so that one piece contains all  the pre-placed P's
and the other piece contains all the pre-placed Q's.


 

Background & Techniques

Another calendar puzzle that is well suited to at least using the computer as a helper.

In the days of hand-set type, print shop apprentices frequently confused the letters "p" and "q" because while all letters appear on the type pieces as mirror images, it happens that these two letters are also mirror images of each other, making it easy to interchange them when setting type. Thus the warning "Mind your p's and q's!" today expanded to mean "Pay attention to the details!"

The two pieces required to solve this puzzle will not only be mirror imaged (flipped about its vertical axis),
but also reversed to top bottom (flipped about its horizontal axis).  Interestingly, and perhaps a clue to help solving these puzzles, these two flips are equivalent to a 180 degree rotation.

Only two puzzles of this type have been found so far and have been included in the download zip files below.  , New puzzles however, can be entered by keying in the size of the grid and the column and row locations of the pre-placed Pa and Qs.  Puzzles may also be saved and reloaded.

Rather drawing heavy outlines, the two pieces are defined by assigning a color to each of the two letters and assigning colors to other grid cells by clicking   Click blank squares to create two patterns of the same shape. Clicking a blank square will fill it with the current Default color. Clicking the Default square or a colored grid square will swap colors in that square and set the Default color to the new color. 

A "Congratulations" message will be displayed when the puzzle has been solved.

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:

A StringGrid is used to display the puzzle.  Since the grid cell colors are changed by clicking and must be capable of being redrawn at any time, I used 2 character strings to control cell appearance.  The first character contains indicates color ("1" for P color, "2" for Q color and a space character for the empty grid color.  The second character in the string indicates the character to be displayed ("P", "Q" is space).   A MousUp event exit sets cell values and a StringGrid DrawCell event exit draws the cell with the color and character indicated by the cell's contents.  

The other significant piece of code check for solution checks for a solution by checking if each cell has the opposite color as the cell at the same distance from the bottom-right corner as this cell is from the top-left corner.  I haven't yet proved that all puzzles must meet this condition, but it is true for the samples I have found, Any samples I have constructed which do not fit this rule are trivial. .      

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source 

Suggestions for Further Explorations

Allow user to define puzzles by clicking on grid
.Implement a programmed solution search.
   

 

Original:  March 14, 2015

Modified:  May 15, 2018

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