38

Is it possible to fill the $121$ entries in an $11\times11$ square with the values $0,+1,-1$, so that the row sums and column sums are $22$ distinct numbers?

Gamow
  • 45,573
  • 10
  • 147
  • 381
  • 2
    Seems like a relatively simple dynamic programming or backtracking problem – qwr Jan 06 '16 at 15:01
  • 4
    I suspect that it is impossible for all odd sized squares, given that it's easy to brute force squares 3x3 and 5x5, and those have no solutions. – qwr Jan 08 '16 at 05:19
  • 3
    @Gamow Do you know the solution? – xnor Jan 11 '16 at 22:30
  • @Gamow please feel free to answer question for bounty. – martin Jan 13 '16 at 13:49
  • I imagine the answer is no if no-one has got it yet – Beastly Gerbil Jan 15 '16 at 19:23
  • 4
    I ask this question of mathoverflow, it is impossible, see http://mathoverflow.net/questions/228525/reverse-definition-for-magic-square –  Jan 16 '16 at 13:24
  • @MeysamGhahramani The joy in doing these problems is found in personally (or with others in real-time) deriving an elegant, general proof, possibly going through an ugly, specific case. Admittedly, we are (or at least I am) currently at an ugly detour stage. Nevertheless, thank you for noting the solution - it gives some incentive to continue the journey. – Lawrence Jan 18 '16 at 16:21
  • is there a solution or people are wasting their time to proof it is not possible? – Oray Jan 20 '16 at 05:59

9 Answers9

14

I've found a solution here, which I've decided to blatantly steal since I think a lot of people really want to see a fully worked out solution. It is indeed impossible. The same method below can be used to show that a valid $n\times n$ matrix can only exist if $n$ is even and the missing sum is $\pm n$.

Let's say the missing sum is $m$. We can assume by symmetry that $m\le 0$. There are 11 rows and columns whose sum is positive. Let's rearrange these positive row/columns so that they are all on the top/left of the matrix. Assuming there are $r$ positive rows, this means there are $11-r$ positive columns. Let's group all the positive columns on the left, and all positive rows on top. See the picture at the bottom, where I've given labels A, B, C and D to four quadrants of the matrix.

Now, let $a$ be the sum of the numbers in section A, and the same with $b,c,d$. Then $$\begin{align} a+b+c+d &=(\text{sum of all rows and columns})/2\\ &=((-11)+(-10)+\dots+11-m)/2\\ &=-m/2 \end{align}$$ We also know that $$ \begin{align} (a+b)+(a+c) &=\text{sum of all positive rows/columns}\\ &=1+2+\dots+11\\ &=66 \end{align}$$ Combining these last two observations, $$ -m/2=a+b+c+d=(2a+b+c)-a+d=66-a+d $$ Here's the kicker. There are $r(11-r)$ entries in section $A$, meaning that $a\le r(11-r)$. No matter what $r$ is, the quantity $r(11-r)$ is at most $30^*$. Similarly, $d\ge -30$. This means that $$ -m/2\ge 66-30-30=6, $$ implying that $m\le -12$, a contradiction.

enter image description here


${}^*$ To make this proof to work for a general $n\times n$ matrix, instead of just $n=11$, use the inequality $ab\le (a+b)^2/4$, which shows $r(n-r)\le n^2/4$. We then get that $-m/2=\frac{n(n+1)}2-a+d\ge \frac{n(n+1)}2-\frac{n^2}4-\frac{n^2}4=n/2$, implying that $m\le -n$, which means $m=-n$. Since the missing sum must be even, this means $n$ must be even.

Mike Earnest
  • 32,336
  • 6
  • 92
  • 237
12

Partial answer (fixing earlier mistake)

The possible outcomes of a sum of 11 values (0, +1 or -1) can be any integer number from - 11 to + 11, leaving 23 options total.

Theory on combining resulting numbers:

It's fairly trivial to state that if '11' occurs (a row/column with all 1's), there can never be a column/row totalling '-11' or '-10', due to one of the rows/columns holding a '1' (you can at lowest reach -9 then). The other way around, you cannot have '-11' and expect to be able to squeeze in 10 or 11.

What we learn from this:

11 and -11 cannot occur in scenario's with one of them in a column, and the other in a row

Note: the above is where I went wrong: I first assumed they couldn't appear together at all, which is false - as pointed out in the comments

For ease of further explanation, assume both 11 and -11 to be in rows (all that follows would be similar but mirrored along the diagonal).

If 11 and -11 both take up an entire row, this means in columns you can at extremes reach -9 and +9. If we want 10 and -10 to be able to appear, those have to be in rows aswell (with 10x '1' or '-1' and one zero). This means we already have 4 rows occupied.

It now gets harder though:

if we aligned the 'zeroes' from the '10' and '-10' rows below eachother, we can get at most +7 and -7 in a column, if we didn't we can get +8 or -8 at most. Either way we can only create +9 and -9 in rows again. We can do this two ways: 9x '+-1' and 2x 0, or 10x '+-1' and 1x '-+1'

What can we squeeze into columns now?

so far, the rows from -11 and 11 cancel eachother out, the rows from -10 and 10 allow for a maximum of +1 or -1 variance on the two rows occupied, and the rows from -9 and 9 for a +2 or -2 variance on the two rows those occupy. So with 5 rows left a column value can now hold at most +-5 (+-3) , which also implies we can now actually squeeze our next step (+8 and -8) into columns.

Option 1: Put the '8's in columns.

This means we've used up all variance on the remaining 9 columns, so we have 9 columns which can at most hold +-5. This also implies both 7's and 6's will have to go in rows. The 11's, 10's, 9's, 7's and 6's hog a combined 10 out of a possible 11 rows.
Is there a way to build the 7's and 6's in the column's that leaves sufficient different value numbers to be built in the colums? This will most likely imply 7's and 6's to be built to a maximum from -1 and +1's rather then 0's, to allow sufficiëntly high values in the collumns). Key might be to try and ensure the presence of the +-4 and +-3 in the colums as a guide to figure out how to place the several +-1's to create 6/7 rows.

Option 2: Put the '8's in rows

It's not because we CAN put the 8's in columns, we have to.

Option 3: Put one of the 8's in a column, the other in a row.

Besides option one and two, there's still a third option, and that's to go both ways.

I may have to put this train of thoughts on hold for now, as there doesn't appear a simple path further down. The thing is: The more you keep pushing things with very similar patterns for the '+' and '-' variation in rows, the bigger the chances you'll have issues fitting in 5's and 4's in columns. If the '+1' and the '-1' from the '+' and '-' version of the larger sums keep cancelling eachother out in the column totals, suddenly it appears 4's and 5's turn seemingly impossible to fit in. (or maybe I just haven't spotted how).

Tim Couwelier
  • 4,349
  • 21
  • 37
  • 3
    That was my first thought also initially but both 11 en -11 can exist easily. fill the first row with +1 and the second row with -1. It's just that when a row has 11 a column can't have -11 – Ivo Jan 06 '16 at 09:17
  • 1
    @dmg - thanks for the spoiler edit - I'm somehow always struggling to put multi-line blocks in spoilers – Tim Couwelier Jan 06 '16 at 09:17
  • @IvoBeckers : Oh dear. This seemed to easy for a question by gamow.. I'll try to build on it though – Tim Couwelier Jan 06 '16 at 09:19
  • @TimCouwelier You can use
    for line breaks in spoilers.
    – dmg Jan 06 '16 at 09:22
  • 3
    @TimCouwelier but I think this is the right track to take. Let's say that if both 11 and -11 exist and they both are rows you also know that the columns can only range from -9 to 9 meaning that -10 and 10 also must be rows, and maybe you can go on like that – Ivo Jan 06 '16 at 09:22
8

Partial answer

As Tim pointed out

If you have rows with sums of -11, 11 and 10, that quickly limits the different numbers you can generate in the columns. Experimentally you can fit in ±11, ±10, ±9, ±8, ±7, ±6 and ±5 but there isn't anywhere to put ±4. If I miss out -10 then I can get to ±3 but there isn't anywhere to put ±2.

And the big problem is that

you need at least ±11 and one of ±10 just to be able to complete the square.

This is because

the row and columns use 22 of the 23 sums but they must sum to the same number so the missing sum must be even.

By contrast, even squares are quite easy; there's a simple pattern whereby you fill a 2n square with n 0s, 2n² 1s and 2n²-n -1s. (Hint: 2n²-n = 2n(2n-1)/2.) Example for 6x6:

1  1  1  1  1  1  6
1 1 1 1 1 -1 4
1 1 1 1 -1 -1 2
1 1 0 -1 -1 -1 -1
1 0 -1 -1 -1 -1 -3
0 -1 -1 -1 -1 -1 -5
5 3 1 0 -2 -4

My best effort so far for 11x11:

 1  1  1  1  1  1  1  1  1  1  1 11
 1  1  1  1  1  1  1  1  1  1  0 10
 1  1  1  1  1  1  1  1  1  0 -1  8
 1  1  1  1  1  1  1  1  0 -1 -1  6
 1  1  1  1  1  1  1  0 -1 -1 -1  4
 1  1  1  1  0  0  0  0 -1 -1 -1  1
 1  1  1  1 -1 -1 -1 -1 -1 -1 -1 -3
 1  1  1 -1 -1 -1 -1 -1 -1 -1 -1 -5
 1  1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -7
 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -9
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -11
 9  7  5  3  0  0  0 -1 -4 -6 -8

As you can see ±2 are missing, but I'm sure that the fact that you can't get those diagonals to meet must be a factor somehow.

Neil
  • 423
  • 4
  • 7
  • Could we, based on the column/row sums matching, figure out that if only 22 out of 23 possible combinations are formed, which of the 23 are options for the one NOT being used? (I.E. '0', 'any odd number', 'any even number, ..') This could make it easier to figure out if any number strictly HAS to be in there. – Tim Couwelier Jan 06 '16 at 13:11
  • 1
    Didn't I answer that in my third spoiler? – Neil Jan 06 '16 at 17:36
  • 1
    If you make one of the zeros in the 5th, 6th, or 7th columns a 1, you'll get a 2 on the right side and a 1 on the bottom, getting you a step closer. – Ian MacDonald Jan 06 '16 at 19:24
7

Taking the example:

enter image description here

for $n=6$, where the greyed cells are the totals of their respective columns and rows, and the top-left cell is the total of each greyed column/row, I am fairly certain that it is not possible for the following reasons:

1) The top-left cell must $=\pm n/2$

2) The only excluded integer in the range $[-n,n]$ must be either $-n$ or $n$.

As noted by @kaine below, these statements are identical, so a proof of either would be enough to show that solutions are not possible for odd $n$. Both are purely observational though, and the bounty will go to a proof (or disproof?!) of the above.

NB

This Mathematica code doesn't check all possiblilities (rather large for $n=11$), but checks the most likely (and returns nothing for test@11).

martin
  • 1,979
  • 1
  • 11
  • 17
  • @kaine that's because I've set the tollerance to only include 1 zero per row/column (reduces computation for larger $n$). Can provide complete code for $n$ if desired, but computational time increases exponentially (hence cutbacks). Please let me know if you require complete solution code. – martin Jan 11 '16 at 20:59
  • @kaine alternatively, increase tollerance by adding && \[Or] Count[#, 0] == 2, etc. to test[n_] function. I addition to including all zeros, for complete check, change Subsets to Tuples. You will see then why I cut back! – martin Jan 11 '16 at 21:02
  • 1
    Um, I'm not sure what you mean by that. I just mean that since the sum of all rows ($R$) equals the sum of all columns ($R=C$) which equals the sum half the sum of all numbers ($\sum_{x=-n}^nx=0$) minus the missing number $y$. This means $\sum_{x=-n}^nx-y=R+C$ goes to $R=C=-y/2$. If you assume 2, 1 is true. If you assume 1, 2 is true. Those two statements are indistinguishable. – kaine Jan 11 '16 at 21:06