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?

  • $\begingroup$ @Sp3000 9x3=27 not 45. With solution i mention a possible sudoku sollution. $\endgroup$ – user3328090 Jan 31 '17 at 10:46
  • $\begingroup$ @Sp3000 meant 5, I guess. $\endgroup$ – Glorfindel Jan 31 '17 at 10:47
  • $\begingroup$ @Glorfindel Yes with 5 all sums=45. Is any other possible way to achive that sums? $\endgroup$ – user3328090 Jan 31 '17 at 10:52
  • $\begingroup$ @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. $\endgroup$ – user3328090 Jan 31 '17 at 11:03
  • $\begingroup$ 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? $\endgroup$ – elias Jan 31 '17 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.

| improve this answer | |
  • 1
    $\begingroup$ That's a very neat method. BTW, instead of the triplets 459/378, you could have used 156/237, 348/267, or 168/249. $\endgroup$ – Jaap Scherphuis Jan 31 '17 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,8,8,7,4,3,3,3,1  *
 9,7,7,7,6,3,2,2,2  *
 9,8,7,6,5,4,3,2,1  * <- normal set of digits
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.

| improve this answer | |
  • 2
    $\begingroup$ Before anyone asks, adding in the sum of cubes = 2025 condition, reduces the number of solutions to 3. $\endgroup$ – Neil W Jan 31 '17 at 12:55
  • $\begingroup$ Thanks @NeilW, I have added that info to my answer. $\endgroup$ – Jaap Scherphuis Jan 31 '17 at 13:02
  • $\begingroup$ 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. $\endgroup$ – Kruga Jan 31 '17 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.

enter image description here

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

| improve this answer | |
  • $\begingroup$ You are correct. If i check the square of the numbers total? $\endgroup$ – user3328090 Jan 31 '17 at 11:25
  • $\begingroup$ You mean $1^2+2^2+3^2+...+9^2 = 285$? $\endgroup$ – Neil W Jan 31 '17 at 11:35
  • $\begingroup$ Yes that i mean $\endgroup$ – user3328090 Jan 31 '17 at 11:39
  • $\begingroup$ 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 $\endgroup$ – Neil W Jan 31 '17 at 11:47

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