# Does this mathy square have any solutions? (And how many?)

Consider a $5\times5$ grid of math operators and numbers that encodes 8 math equations:

A + B = C
= + + + +
D + E = F
+ = = = =
G = H + I


There are 3 horizontal equations, 3 vertical, and 2 diagonal. Specifically:

A + B = C
D + E = F
H + I = G
D + G = A
B + E = H
C + F = I
A + E = I
C + E = G


However, to make the grid less strict, each equation has 3 additional allowed forms:

• The + can be replaced with *. e.g. A * B = C. (We'll avoid - / ^ since they aren't commutative.)

• The + and = can be swapped. e.g. A = B + C.

• Both of the above. e.g. A = B * C.

Thus you can massage the equations a bit in order to form a more workable grid. For example, it might look like:

A * B = C
+ = * * +
D = E * F
= = = + =
G * H = I


The question is: Can the letters A through I be replaced with all one-digit numbers 1 through 9 in any order such that all 8 grid equations are satisfied?

Are there lots of solutions or none at all?

(Bonus: What if - or / or ^ is allowed to be an operator (and you make some assumptions about reading direction).)

• Do you mean can we have 9 unique digits?! I rather doubt it, at least without subtraction or division. – Jonathan Allan Aug 23 '16 at 6:06
• If you allow duplicated digits there is a trivial example. – Taemyr Aug 23 '16 at 9:06

Partial math solutions for the default grid:

it is not possible in the default configuration:

Reasoning:

Consider these 3 equations:
$A+B = C$
$C+E = G$
$D+G = A$
Summing them up we get
$A+B+C+D+E+G = A+C+G$
subtracting $A+C+G$ from both sides we get
$B+D+E = 0$.
This is not possible if all 3 letters represent positive distinct digits.

Still working on the "mutated" grid.

If the C# program I wrote is correct, then there are no solutions. In fact, even if you leave out the two diagonals, there still aren't any.

   class Program
{
static void Main(string[] args){
int[] board = new int;
bool[] used = new bool;
searchMagic(board, used, 0);
}
static void searchMagic(int[] board, bool[] used, int depth) {
if (depth == 9) {
foreach (int v in board) {
Console.Write(v);
}
Console.WriteLine();
return;
}
for (int k = 1; k <= 9; k++) {
if (!used[k-1]) {
board[depth] = k;
used[k-1] = true;
if (checkboard(board, depth)) {
searchMagic(board, used, depth + 1);
}
used[k-1] = false;
}
}
}

  static int[] triplets ={0,1,2, 3,4,5, 6,7,8, 0,3,6, 1,4,7, 2,5,8,
0,4,8, 2,4,6 };
static bool checkboard(int[] board, int last) {
for (int i = 0; i < triplets.Length; i += 3) {
if (triplets[i + 2] <= last) {
if (!TripletIsOk(board[triplets[i]], board[triplets[i + 1]], board[triplets[i + 2]])) return false;
}
}
return true;
}
static bool TripletIsOk(int a, int b, int c) {
return a + b == c || a == b + c || a * b == c || a == b * c || a + c == b || a * c == b;
}
}

• I reached the same conclusion with the help of a python script. Seems to be the correct answer. – elias Aug 23 '16 at 7:24

As @JaapScherphuis already pointed out, there is no solution, even for the weaker criteria without the diagonals. (I'm reading both diagonals from top to bottom.) Here are the possible solutions in which all the rows and the first two columns are of the desired form - none of them having a third column which can be used as any of the listed expressions:

1+7=8
+ =
3x2=6
= +
4+5=9
-----
1+7=8
+ =
5+4=9
= +
6=3x2
-----
2x3=6
+ +
7+1=8
= =
9=4+5
-----
4+5=9
= +
3x2=6
+ =
1+7=8
-----
5+4=9
+ =
2x3=6
= +
7+1=8
-----
6=3x2
= +
5+4=9
+ =
1+7=8
-----
7+1=8
= +
2x3=6
+ =
5+4=9
-----
7+1=8
+ +
2x3=6
= =
9=4+5
-----
9=4+5
= =
2x3=6
+ +
7+1=8
-----
9=4+5
= =
7+1=8
+ +
2x3=6


Answering the bonus question: still no solutions after introducing x-y=z, x=y-z, x/y=z, x=y/z, x^y=z and x=y^z as allowed expressions. Not even without the diagonals.

However, after adding modular arithmetic and bitwise operations, there are several solutions, one of them being:

9=4+5
==+%|
8=2^3
+==+=
1+6=7


(% is for modulo, | is bitwise or, ^ is exponentiation, + is addition)

This is not a strict answer, but a long comment.

A (less elegant, yet feasible) reformulation of OP's question could be:

Is it possible to arrange the numbers

2, 4, 5, 8, 10, 12, 14, 18, 20

into a 3x3 grid as shown in OP, to have 8 meaningful equations with the operands + and *? There is a single principal solution (and four rotations and twofold transposition leads to another 7).

  4  *  5  = 20
+  *  *  =  =
14  =  2  + 12
=  +  =  =  +
18  = 10  +  8

• The OP is asking for single-digit solutions, though ... – Glorfindel Aug 23 '16 at 11:23
• @Glorfindel ...and this answer already stipulated a "reformulation of the OP's question", which is in line with every other answer here where there is no solution based on the current question but a potential answer with a reformulation of the question. – Keeta - reinstate Monica Aug 23 '16 at 13:28