5x5 bimagic search technique
by Lee Morgenstern, January 2014.


     A B C D E
     F G H I J
     K L M N P
     Q R S T U
     V W X Y Z

for MaxNo = 12 to 1000   [and hopefully greater]
for PartialSum = (MaxNo + 66)/3 to 2(MaxNo + 1)   [see Note 1]

List all 4-entry series adding to PartialSum using 1 to MaxNo.
Sort the series by their sum of squares.

for each group of three disjoint series
   with the same sum and sum of squares
   that contain both 1 and MaxNo          [see Note 2]
   assign them to A,G,T,Z and E,I,R,V and C,H,S,X such that

   E + I + R + V  =  A + G + T + Z  =  C + H + S + X
   E + I + R + V  =  A + G + T + Z  =  C + H + S + X

for each permutation of the 12 entries that satisfies the above,

   Avoid permutations that can be reached by a rotation, reflection, etc.
   Delay permutations until they are needed.   [see Note 3]

   3 choices for C,H,S,X line
   3 choices for (A,Z),(G,T) combo    AGTZ AGZT AZTG
   6 choices for (E,V),(I,R) combo
   6 choices for (C,X),(H,S) combo

Solve for L and N using Formula 1.
   L + N = A + Z + E + V + C + X - G - T - I - R
   L + N = A + Z + E + V + C + X - G - T - I - R Reject if not rational.

Solve for K and P using Formula 1.
   K + P = A + Z + G + T - L - N
   K + P = A + Z + G + T - L - N Reject if not rational.

for each permutation involving swapping
   E,V;  I,R;  K,P;  H,S   [16 permutations]

Solve for J and Q using Formula 2.
   J - Q = A + K + V - G - H - I
   J - Q = A + K + V - G - H - I Reject if not integer.

Solve for U and M using Formula 2.
U - M = A + G + Z - Q - R - S
U - M = A + G + Z - Q - R - S Reject if not integer.

Compute F = G + M + T + Z - K - V - Q
Verify F = G + M + T + Z - K - V - Q Reject if not equal.

for each permutation involving swapping
   L,N;  C,X  [4 permutations]

Solve for W and D using Formula 2.
   W - D = A + C + E - G - L - R
   W - D = A + C + E - G - L - R Reject if not integer.

Compute Y = A + G + Z + M - D - I - N
Verify Y = A + G + Z + M - D - I - N Reject if not equal.

Compute B = G + T + Z + M - C - D - E
Verify B = G + T + Z + M - C - D - E Reject if not equal.

Output solution.


Formula 1

Given a and b, find x and y such that
   x + y = a
   x + y = b

   x = (a + c)/2
   y = (a - c)/2
         where c = 2b - a

Reject if c is not rational.
Note that if a and b are integer and c is rational, then x and y will be integers.
Note also that the values of x and y can be swapped.

Formula 2

Given a and b, find x and y such that
   x - y = a
   x - y = b

This always has the rational solution
   x = (b/a + a)/2
   y = (b/a - a)/2
but may not be integer.


Note 1.

The highest PartialSum value is 2(MaxNo + 1).
If a bimagic square existed with a higher partial sum, you could subtract all of its entries from (MaxNo + 1) and get another bimagic square with a partial sum smaller than 2(MaxNo + 1) for the initial three series, which would have been found by an earlier search.

Note 2.

1 and MaxNo are required to be in the initial 12 entries.
If they weren't and a bimagic square was found, you could translate this solution to a range using a smaller value of MaxNo, which would have been found by an earlier search.

Note 3.

The computation of L,N and K,P results in the same values if E and V are swapped, for example. If these extra swaps are done and the computation of L,N or K,P is rejected, you would be rejecting the same thing multiple times.


Return to the home page http://www.multimagie.com