[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
|
|
Problem Description
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.
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? J. J. Clessa. Problem # 64 Background & TechniquesHere'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
Suggestions for Further ExplorationsI'll be back when I think of something. Rotate counterclockwise?
|
[Feedback] [Newsletters (subscribe/view)] [About me]Copyright © 2000-2018, Gary Darby All rights reserved. |