Durer's Magic Square

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




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


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

Search DelphiForFun.org only




Problem Description

Dürer's Magic Square is contained in a famous copper engraving, "Melancholia", created in 1514 by German artist Albrecht Dürer.

There are 86 different combinations of four numbers from the square that sum to it's magic number, 34! 

How many can you find? 

Background & Techniques

Albrecht Dürer is generally considered to be  Germany's most famous Renaissance artist.   He was about 20 years younger than Leonardo da Vinci and around 1500 became greatly interested in the relationship between mathematics and art.  Leonardo and his contemporary, mathematician Pacioli, almost certainly influenced Dürer in these studies.   In 1514 he created the copperplate engraving named "Melancholia I" which contained this magic square - the first magic square published in Europe.  (Notice that the creation date of the picture, 1514, is contained in the bottom row of the square.) 

The program will sequentially display all 86 ways to pick four numbers that sum to 34.  The button to start this display is hidden until the user has identified 20 solutions.  The first 20 or so are not too difficult to find.  After that, finding solutions by inspection becomes increasingly difficult.  I have yet to find more than 40 solutions - and I have watched the program solution several times!   

The programming for this problem is fairly straightforward.  A StringGrid is used to display the square and an OnDrawCell exit to highlight the current set of selected cells, whether selected by the user or the program.  To accomplish this, an array of strings, S, contains the selected cell values.  As each cell is drawn, its value is compared to the values in S and if a match is found, the cell is highlighted.     User solutions are placed in a Listbox Stringlist.  In order to block duplicate solutions, we sort the four numbers before adding them to the list so that  Items.IndexOf procedure can  be used to check for duplicate solutions.   

Addendum  September 8,. 2003:  Viewer Don Rowland recently noticed a minor problem while finding solutions -  the program allowed the same square to be selected more than once.  Together we came with the fix which was posted today. . 

Running/Exploring the Program 

bulletBrowse source extract
bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

I wonder - how many of the 86 solutions are symmetric?   I haven't really made a study of symmetry but it seems that a solution would be symmetrical if you could fold the square along a straight line so that the solution squares overlapped exactly.   Is  flipping and rotating the square the same logical operation as folding? 



Original Date: January 19, 2003 

Modified: May 15, 2018

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