Rotating Grid

[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

5 8 3
1 4 6
7 2 9

In the grid shown, the digits 1-9 are arranged so that the first row added to the second row equals the bottom row -- 583+146=729.

 

 

 

7 1 5
2 4 8
9 6 3

Now if the grid is rotated clockwise through 90 degrees, you will see that the first two rows still add up to the last row -- 715+248=963.

 

 

 

 

 

Can you find another combination of the digits 1-9 which has the same property?

Source: Math and Logic Puzzles for PC Enthusiasts, 

J. J. Clessa. Problem # 64

Background & Techniques

Here's another program that uses the permutation algorithms developed in Permutes1 (the first programs was Alphametics). 

We'll  generate all possible permutations of the numerals 1-9 and, for each, check  to see if the conditions are met.  Remember there are 9! (9x8x7...x2x1) permutations of 9 things taken 9 at a time, so we only have about 360,000 to check.   We must convert the three integers to a single number before testing.  We can do this by multiplying the first digit (the thousands position) by 1000, adding it to 100 times the 2nd digit and then adding the rightmost digit.  To find a solution, we'll have to do this for the numbers represented by the 3 rows and the 3 columns.

There is one more perhaps new coding technique here; A stringgrid is used to display the result.  One of the features of a stringgrid is that the user can select a cell to trigger some action, even though we're not doing that here.  However the currently selected sell (by default the first cell) is highlighted to show that it's selected.   To un-color this cell I used a DrawCell exit called each time a cell is displayed.  The exit simply clears the cell and writes the digit.  

Running/Exploring the Program 

bulletBrowse source code extract
bulletDownload Source
bulletDownload executable 

Suggestions for Further Explorations

I'll be back when I think of something.  Rotate counterclockwise?

 

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