Downloads

Freeware Disclaimer

The software on this site may be used freely.
You should use only if you agree to the freeware disclaimer.

The programs here are Microsoft® Visual C++® Console Applications.

To make a copy of a console:
  Click the upper left corner button, and Edit, Select All.
  Click the upper left corner button, and Edit, Copy.
  Paste to a text file.

To paste input, such as, a file name, into a console:
  Copy the file name from somewhere.
  Click the upper left corner button, and Edit, Paste.

There are source code files and Win32 applications for the programs described below.

Note: Run times are for a 2.2 GHz PC.

Adjacent

AdjacentCornerSquares C code
Makes adjacent corner pair magic squares. Output files are in folder AdjacentCornerSquares[_n].

AdjacentSideSquares C code
Makes adjacent side pair magic squares. Output files are in folder AdjacentSideSquares[_n].

Associative

AssociativeSquares C code
Makes associative magic squares. For singly-even order the squares are near-associative. Output files are in folder AssociativeSquares[_n].

Bordered

BorderedSquare C code
Makes bordered magic squares. Makes one square of each order. All these squares have zero water retention. Output files are in folder BorderedSquare[_n].

BorderedSquare1 C code
An earlier version using an algorithm developed for the HP-41C pocket calculator. The odd order squares are the same as made by BorderedSquare, but the even squares are different, (not zero water retention). Output files are in folder BorderedSquare[_n].

BorderedSquares C code
Makes bordered magic squares. Makes many distinct squares by randomly:

Output files are in folder BorderedSquares[_n].

BorderedSquares1 C code
An earlier version that made many fewer distinct squares, only randomly rotating each nested border and the center. Output files are in folder BorderedSquares[_n].

Bordering

BorderingSquares C code
Makes bordering magic squares. Output files are in folder BorderingSquares[_n].

Composite

CompositeSquares C code
Makes composite magic squares of order mn from input squares of order m and order n. Output files are in folder <M>-<N>-CompositeSquares[_n].

CompositeCalligraphy C code
Makes squares showing the content of text files as retained water. See notes.

Each square is a composite of order mn made from magic character squares of order m and a square of order n. Order m = 11 and order n is calculated as the greater of:

The character squares are contained in the program. Optionally, the program also supplies the order n square, which will be a zero retention magic square. If the order n square is magic, the composite is magic. Output files are in folder <M>-<N>-Composite[_n].

Franklin

FranklinMagicSquares C code
Makes Franklin magic squares. Output files are in folder FranklinNormalMagicSquares[_n].

Magic

MagicSquares C code
This program makes magic squares. The square type can be specified as semimagic, magic, or associative. See notes and CompleteSquare. The output file is <N>x<N><square type>[_n].txt.

Most-perfect

Most-perfectSquares C code
Makes most-perfect magic squares. Output files are in folder Most-perfectSquares[_n].

Pandiagonal

PandiagonalSquares C code
Makes pandiagonal magic squares. Output files are in folder PandiagonalSquares[_n].

Reversible

ReversibleSquares C code
Makes principal reversible squares. Writes to the console the number of principal squares made and the calculated number of variations of each and total reversible squares. Output files are in folder ReversibleSquares[_n].

Self-complement

SelfComplementSquares C code
Makes side-to-side symmetric self-complement even order magic squares. Output files are in folder SelfComplementSquares[_n].
To make associative self-complement magic squares, use program AssociativeSquares

Symlateral

SymlateralSquares C code
Makes symlateral magic squares. Output files are in folder SymlateralSquares[_n].

Zigzag2

Zigzag2Squares C code
Makes zigzag2 magic squares. Output files are in folder ZigZag2[_n].

Order 4

Order4 C code
Makes the 880 order 4 magic squares. Output is a .txt file.

Order 5

Order5 C code
Makes the 275,305,224 order 5 magic squares.

Files are output in folder Order5[_n]. There are 25 .txt files, one each for the squares with the same center value. The files contain only the squares in a single column. Numbers are separated by white space characters, (blank, newline).

WARNING: The files are large, ranging from 341 MB to 1,492 MB, (total 21 GB).

Order5Special C code
Makes special order 5 magic squares. The types made are associative, concentric, bordered, inlaid corner, inlaid side, pandiagonal, ultramagic. Files are output in folder Order5Special[_n].

Order5CountTime: 7 minutes C code
Computes the number of order 5 magic squares. Only the source code is provided.

Order 6 Concentric

Order6C C code
Makes 4x4 center squares and border groups. For an input range of partitions, the output is:

See Order6CDoc.txt and Order6CExamples.txt. Output files are in folder Order6C[_n].

Order6CSample C code
Makes a sample of the squares. One square is output for each of the center/border partitions, (22,145 squares). Output is a .txt file.

Order6CcountTime: 5 minutes C code
Computes the number of order 6 concentric magic squares, (736,347,893,760). Only the source code is provided.

Order 7

Order7Ccount Time: 4 h 40 m C code
Computes the number of order 7 concentric magic squares, (3,835,791,613,181,952,000). See Order7CDoc.txt. Only the source code is provided.

Order7BentDiagonal On HP Z800 @2.40GHz: 3h 34m C code
Makes the order 7 bentdiagonal magic squares, (21,446). Only the source code is provided. It is adapted from Quick Basic program 7x7BDM-H written by Miguel Angel Amela of Argentina.

Order 8

Franklin8 C code
Makes the 368,640 magic and 737,280 semi-magic order 8 Franklin squares. Output files are in folder Order8Franklin[_n].

Most-perfect8 C code
Makes the 368,640 order 8 most-perfect magic squares. Output file is Order8Most-perfectSquares[_n].txt.

Utility Programs

Input for these programs is a .txt file containing one or more number squares of the same order. The text file must contain only the square numbers separated by white space characters, (blank, horizontal tab, newline).

You will be prompted first to input the order of the squares, and, then the file name. The file name can be the absolute path name or the path name relative to the folder containing the program. It is not necessary to enter the .txt extension. For example, if program Frenicle is in folder C:\Squares and the file is C:\Squares\order4squares.txt, the file name can be entered as any of:

Bones C code
Changes squares to or from bones format. Square numbers must be in the range 1 to n² or 0 to n²-1 for sensible results. Output .html file(s) are in folder ToFromBones<N>[_n]. If the input file is large, output may be split into a number of files.

CompleteSquare C code
Given an input square with some cell values between 1 and n² specified, (and other cell values 0), this program attempts to complete a magic square by placing the remaining values. The square type can be semimagic, magic, or associative. See notes. The output file is <N>x<N><square type>[_n].txt.

The program fills the starting square with random placement of unspecified values, and then uses "Constraint-Based Local Search" and "Tabu Search" techniques to transform the square into the indicated type. See "Water Retention on Magic Squares Solver" by Johan Öfverstedt.

Thanks to Craig Knecht for pushing the envelope here.

CompleteSquareSteps C code
Similar to CompleteSquare, but, for successful solutions, shows the steps of the computation. The number exchanges at each step and the intermediate squares are written to files. See related animation by Craig Knecht. The maximum number of steps is set at 1000.

CopySquaresByNumber C code
Copies squares from a file. Squares to copy are chosen by a number or number range. The output file is Order<N>Copy<num>[_n].txt or Order<N>Copy<num1>to<num2>[_n].txt

CopySquaresByType C code
Copies squares from a file. Squares to copy are chosen by include and exclude type lists. The output file is Order<N>Copy[_n].txt

Frenicle C code
Puts squares in Frénicle standard form and sorts them in ascending order. The number of duplicate squares is reported and duplicates are not output. The output file is <in file name>Frenicle[_n].txt

Frenicle64 C code
A 64 bit version of Frenicle that can sort much bigger files if enough RAM is available. Requires a little over 9 GB of RAM to sort a single 21 GB file of all the Order5 magic squares.

GetMagic C code
Checks if squares are magic. The program classifies each square as normal magic, other magic, or not magic. If the squares are not all of the same class, they are written to separate files: NormalMagic, OtherMagic, NotMagic. The files are written to folder Order<N>Squares[_n].

GetType C code
Checks the type of each square as: not magic, normal semimagic, other semimagic, normal magic, other magic. If the type is normal magic, checks other properties : adjacent corner, adjacent side, associative, concentric, bordered, bordering, symlateral, pandiagonal, compact, complete, bent diagonal, Franklin, zigzag, self-complement, bimagic, trimagic. If the type is normal semimagic also checks appropriate properties in the list. See notes. Results are written to <in file name>TypeDetail[_n].txt.

Hurkens C code
Puts Franklin squares in Hurkens principal form. The output file is <in file name>Hurkens[_n].txt

Rotate C code
Rotates squares to a different aspect chosen by the rotation number:

     Number                   Rotation
    --------    -----------------------------------------------------
        0                       none
        1                   clockwise 90°
        2                       180°
        3                counterclockwise 90°

        4       180° about middle vertical or Y axis,   (= mirror)
        5       180° about main forward diagonal,       (= mirror + 1)  
        6       180° about middle horizontal or X axis, (= mirror + 2)  
        7       180° about main back diagonal,          (= mirror + 3)

        8                       all

ZeroOne C code
Converts squares from range 0 .. n2-1 to 1 .. n2 or vice versa. The range to convert to is indicated by input of 0 or 1. Squares that are already in the selected range are copied unchanged. The output file is <in file name>To<0|1>[_n].txt

Transform

Transforms1_2 C code
Transforms squares using transform 1 and/or transform 2. For each squares file, you can do a transform and then opt to do another transform of that transform. If declined, you can opt to do another transform on the original squares. If declined, you can opt to transform another file of squares. The transform is selected by the number of rows entered, (1 or 2).

The flow chart is:


          --------------->--------- enter the order
         ^                                 |
         |                        enter the file name
         |                                 |
         |    ----------->--------- enter the rows(s)
         |   ^   ^                         |
         |   |   |                   transform squares
         |   |   |                         |
         |   |    <- YES <- transform transformed squares?
         ^   ^                             |
         |   |                             NO
         |   |                             |
         |    <----- YES <--- transform original squares?
         |                                 |
         |                                 NO
         |                                 |
          <--------- YES <----- transform another file?
                                           |
                                           NO
                                           |
                                          end

Transforms1_2All C code
For each square in an input file, makes (a sample of) all possible squares from repeated transform 1 and/or transform 2. Output files are in folder Order<N>XForm[_n]. There is one file for each square in the input file. The first square in each output file is the original square.

Complement C code
Makes the complementary squares. The output file is <in file name>Complement[_n].txt.
Self-complement squares are also written to <in file name>SelfComplement[_n].txt

AssocPan C code
For doubly even orders, transforms associative magic squares to or from pandiagonal complete magic squares. Pandiagonal complete squares are written to <in file name>P[_n].txt. Associative squares are written to <in file name>A[_n].txt. All squares are output in Frénicle standard form, (unsorted).

Most-perfectToFranklin C code
For orders that are a multiple of 8, transforms most-perfect squares to Franklin magic squares. Squares are written in unsorted Frénicle standard form to <in file name>F[_n].txt.

ReversibleMost-perfect C code
For doubly even orders, transforms reversible squares to and from most-perfect squares. Most-perfect squares are written to <in file name>MP[_n].txt. Reversible squares are written to <in file name>R[_n].txt. All squares are output in Frénicle standard form, (unsorted).

ReversibleToAssociative C code
For doubly even orders, transforms reversible squares to associative squares. Squares are written in unsorted Frénicle standard form to <in file name>A[_n].txt.

ReversibleToFranklin C code
For orders that are a multiple of 8, transforms reversible squares to Franklin magic squares. Squares are written in unsorted Frénicle standard form to <in file name>F[_n].txt.

Water Retention

WaterRetention C code
Computes and displays the water retention patterns of number squares. Water retention is an idea of Craig Knecht. The program is based on an algorithm of Gareth McCaughan.

See requirements for the input file under the Utility Programs heading. An example text file of the 880 order 4 magic squares is provided. Output .html files are in folder Water<N>[_n]. If the input file is large, output may be split into a number of files. Here is an output example:

WaterRetention3D C code
Displays a 3-dimensional view of water retention. The code for the 3D view was written by Claudio Rocchini during the Zimmermann contest. Land is shown in shades of green, water in blue, and the start of spillways between water bodies or out of the square in yellow. For water, the bottom elevations are shown. Here are examples:

Output files are in folder Water<N>_3D[_n]. The files are in Scalable Vector Graphics (SVG) format. There is one .svg file for each square in the input file.

You may need to install a viewer like Win 98-XP from Adobe, before your browser will open .svg files. Another way is to download and run a program such as Windows - installer from Inkscape. With Inkscape you can open a .svg file and save it as a .png.

WaterRetentionSort C code
Sorts squares in decreasing order of water retention. The number of duplicate squares is reported and duplicates are not output. The output file is <in file name>WRsort[_n].txt. A summary file is also written.

WaterRetentionWithComplement C code
For an input file of squares, finds the maximum water retention for a square and its complement. The square(s) and complement(s) having the maximum combined retention are written to a file. For self-complement squares, the square with the maximum retention is written to a file. A summary is written to the console and a file. The output files are in folder WRwithComplement<N>[_n].

formatZtoW C code
Re-formats squares in Zimmermann contest format to the white space separated format used by programs on this site. Squares are output in folder WfromZ[_n].