Being the author of the code Terrypin quoted, at first I must apologize that I have wasted so many user's precious time by publishing my half-baked code. And I have to confess I am very slowly getting acquainted to writing in English. You still will find the comments and even variable names and self-defined function names in my codes in German. Anyway, I was greatly impressed by the fact that Mr. Bernard Frenicle de Bessy managed to compile the complete list of 4x4 magic squares even before 1675 (his findings were published posthumously) without access to any electronic support, which animated me to do my very best to speed-up my code.
That is why I shifted the numbers from 1-16 to 0-15 in order to have 16 bits (int16_t) to handle the numbers which are still available. I also modified the sequence of setting values in a way that increased the speed slightly, but confused some readers. But all this is history. You may find a recent and faster version at
If you are more interested in magic squares, may I recommend a book published in 2024 by Holger Danielsson: Magische Quadrate und ihre Konstruktion
(sorry, english version not yet available)
The news about finding the number of all 6x6 magic squares in 2024
(is there any hard-disk to store them all?) is obviously out of reach of any arduino ...