I have spent too much time on this question. I am convinced this cannot be done. Please prove me right (or wrong) and explain why.

Below is a 5x5 grid. Digits 1 through 9 go in the 9 yellow boxes. Every digit must be used. Yellow boxes can only contain a single digit, nothing else.Obviously all 9 digits will have to be placed.

Bluish boxes will have the givem Math operators. Only + - * / ^ and = can be used. Nothing else.

enter image description here

Now can a grid be created where all vertical, horizontal and diagonal equations are correct? Direction of the equation not important.

I tried and tried and failed. The closest I came was enter image description here

I got horizontals, diagonals and two of the 3 verticals to work but not the middle.

Can this be done given the restrictions? Why?

Which operators will make this possible, if any.

Please don't say "not equal to" :)

  • $\begingroup$ fun problem, but just wondering where it came from or if you are trying to make up a puzzle. $\endgroup$
    – tom
    Commented Mar 18, 2020 at 13:18
  • $\begingroup$ All my puzzle @tom. I have too much time at hand. BTW I am serious when I say it probably cannot be done. $\endgroup$
    – DrD
    Commented Mar 18, 2020 at 13:19
  • 1
    $\begingroup$ Congrats on 20k reputation! $\endgroup$ Commented Mar 18, 2020 at 14:11
  • $\begingroup$ I did not find a solution by brute force permutation, but I did not finish proving it logically. For that, I began by trying each number in the centre, and then 9 can go in one of two locations, and I could not complete any arrangment. Sadly I gave up at 4, because presenting every attempt exhaustively isn't much fun ;) One point of interest is rot13(gurer jnf ab arrq gb purpx qvivfvba, orpnhfr vg vf pbirerq ol gur erirefr zhygvcyvpngvba). $\endgroup$ Commented Mar 18, 2020 at 14:55
  • $\begingroup$ You could place two plus signs there. $\endgroup$
    – daw
    Commented Mar 18, 2020 at 15:29

2 Answers 2


Using only basic operators (+ - * / ^)

It is not possible but there are many solutions that are missing a single row/column.

This Python program would print all complete solutions if any existed: https://repl.it/repls/OrchidAcceptableNaturaldocs

There are 16 solutions that, like yours, are missing the center column:

There are 64 boards total that are missing any one row, column, or diagonal.

Here is the complete list: https://pastebin.com/dSAnwQhB

and here is the generating code: https://repl.it/repls/BriefWarmInstitutions

If we were to introduce bitwise operators

There are 24 possible solutions, one of which being:

enter image description here

Generating code: https://repl.it/repls/AuthorizedCriminalPagerecognition

Including only OR: 8 boards
Including OR and AND: 24 boards

Including Square Root, Square, and Factorial operations

There are 46 complete boards that involve at least one of sqrt, square, and factorial

For example:


Example with factorial:

enter image description here
Generating code: https://repl.it/repls/WhoppingIncompleteApplicationframework

  • $\begingroup$ Great effort. IF you allow certain operators within the number boxes like ! or Square or square root so you change the numbers themselves it could be possible, right? $\endgroup$
    – DrD
    Commented Mar 19, 2020 at 12:44
  • $\begingroup$ @DEEM There definitely are solutions if you allow sqrt, square, and factorial (likely hundreds). I've found several and hope to have a complete list soon. $\endgroup$ Commented Mar 19, 2020 at 14:40
  • 1
    $\begingroup$ @DEEM Here is an example $\endgroup$ Commented Mar 19, 2020 at 15:15
  • 1
    $\begingroup$ That is great. So there is a Magic square with 1 to 9!! $\endgroup$
    – DrD
    Commented Mar 19, 2020 at 15:28

I used integer linear programming to verify that the problem is infeasible. It turns out that there are 64 near misses with one violation like yours. These reduce to 8 solutions up to symmetry:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.