# Can a 9x9 sudoku with sum 45 and square sum 285 of (rows, columns, 3x3) not be valid? [closed]

I have created a program that checks if a Sudoku solution is correct.

It tries to do so by checking the following:

• Rows, columns, 3x3 grids if the sum of the numbers is 45 $(1+2+3...+9=45)$
• Rows, columns, 3x3 grids if the sum of the squares of the numbers is 285 $(1^2+2^2+3^2+...+9^2=285)$

Is there any way to fool this program with a non-valid Sudoku solution and make it think that it is valid?

• @Sp3000 9x3=27 not 45. With solution i mention a possible sudoku sollution. Jan 31, 2017 at 10:46
• @Sp3000 meant 5, I guess. Jan 31, 2017 at 10:47
• @Glorfindel Yes with 5 all sums=45. Is any other possible way to achive that sums? Jan 31, 2017 at 10:52
• @TheGreatEscaper i disagree with you. Its not optimization. It just logic. I try to find a "solution" with sums of 45 in (rows,collumms,3x3) but this solution to not be a valid sudoku solution. Jan 31, 2017 at 11:03
• The question is a little bit vague for me. Are there any other restrictions regarding the numbers being integer? Or positive? Or one-digit numbers? Jan 31, 2017 at 13:56

I think it can be fooled, even with a grid which has 9 of each digits.

Here is a grid that does it:
378 378 126
459 126 459
126 459 378

594 783 261
783 261 594
261 594 783

945 837 612
837 612 945
612 945 837

Obviously the first two rows break the rules of a Sudoku.
But the sums of the numbers and their squares are all fine.

I constructed this based on the idea that

$4+5+9=3+7+8$ and $4^2+5^2+9^2=3^2+7^2+8^2$ both hold.
So I created a naive correct solution with 459 and 378 in the first two rows of the top left box, and then destroyed it by swapping these two triplets.

• That's a very neat method. BTW, instead of the triplets 459/378, you could have used 156/237, 348/267, or 168/249. Jan 31, 2017 at 13:41

I ran a small computer program to find lists of nine digits that sum to 45 and have a sum of squares of 285. One of these is of course 9,8,7,6,5,4,3,2,1 but there could be others.

And indeed there are. Here are the 25 possibilities my program found:

 8,7,7,7,7,4,2,2,1
8,8,7,6,6,5,3,1,1
8,8,7,7,5,4,4,1,1
8,8,7,7,5,5,2,2,1
8,8,7,7,6,3,3,2,1
8,8,8,5,5,5,4,1,1
8,8,8,6,6,3,2,2,2
8,8,8,7,4,3,3,3,1  *
8,8,8,7,4,4,2,2,2
9,7,6,6,6,6,3,1,1
9,7,7,6,6,4,4,1,1
9,7,7,6,6,5,2,2,1
9,7,7,7,6,3,2,2,2  *
9,8,6,6,5,5,4,1,1
9,8,7,6,5,4,3,2,1  * <- normal set of digits
9,8,7,7,4,3,3,2,2
9,8,8,5,4,4,3,3,1
9,8,8,5,5,3,3,2,2
9,8,8,6,3,3,3,3,2
9,9,6,5,5,4,4,2,1
9,9,6,5,5,5,2,2,2
9,9,6,6,4,4,3,3,1
9,9,6,6,5,3,3,2,2
9,9,7,4,4,4,4,3,1
9,9,7,5,4,4,3,2,2
It may not be immediately obvious that this shows there are false Sudoku solutions that pass the limited validity check in question. Take a valid Sudoku solution, and replace all the 1s by the letter A, 2s by B, etc. Now choose one of the 24 abnormal sets of digits from one of the rows above. Do another substitution, changing the letters A-I by that abnormal set of digits in any order. Each house, row, and column will have one complete set of those digits and so will sum to 45 and have a squared sum of 285.

Edit: As Neil W pointed out, if you also add the check that the sum of the cubes adds to 2025, then there are still two false sets of digits, which I have marked with an asterisk in the list above.

Edit2: I also did a search for all sets of nine digits with sum 45 and product 9!. This leads to only one false set of digits, namely 9,9,7,5,4,4,4,2,1.

• Before anyone asks, adding in the sum of cubes = 2025 condition, reduces the number of solutions to 3. Jan 31, 2017 at 12:55
• Thanks @NeilW, I have added that info to my answer. Jan 31, 2017 at 13:02
• It doesn't say we have to use 1-9. There might be more solutions if you use larger numbers, negative numbers, or even fractions. Jan 31, 2017 at 14:59

Yes if you take a valid solution, like the first grid below, and pick four cells that form the vertices of a rectangle, the vertices being two pairs of vertices sharing a square, then you can adjust the cell values in such a way as to keep the row, column and square totals equal to 45, as seen in the second grid. The changes in value are seen in the third grid where you can see the row, column and square totals are all zero.

Thus when checking for validity, you can't just check the totals, you need to check for the uniqueness of values also.

Clearly you could apply this method many times over to the same grid while still preserving the totals.

• You are correct. If i check the square of the numbers total? Jan 31, 2017 at 11:25
• You mean $1^2+2^2+3^2+...+9^2 = 285$? Jan 31, 2017 at 11:35
• Yes that i mean Jan 31, 2017 at 11:39
• It might not be enough in itself, since $5^2+5^2 = 1^2 + 7^2$ but if you checked the sum of the numbers, and the sum of the squares of the numbers, that might be enough. That's perhaps a question best answered at math.stackexchange.com Jan 31, 2017 at 11:47