[Math] Does a solved sudoku game always have same sum? Is this sum unique to solved game

puzzle

Fundamentally, I'm looking for help on two things:

  1. Verification that my math is correct for the assumption that all Xs are Y.

  2. Proof that are the inverse is true, that all Y's are X, or, if it's not true, example of X that is outside the Y set.

More specifically, the assumption is :

  1. All solved Sudoku puzzles, where "solved" is defined as a 9×9 grid having the set 1-9 in each column, row, and 3×3 quadrant, can be verified as solved by taking the sum of each row, column, and quadrant, as the sum will always be 1215. This is based on taking the sum of each digit in the set (1+9 + 8+2 + 7+3 + 4+6 + 5 = 45) and multiplying by the total number of sets (9 rows + 9 columns + 9 quadrants = 27), so 45 * 27 = 1215.

  2. If the assumption above is correct, is this sum unique to solved puzzles, or are there permutations of a completed (but not solved) board that would give 1215 using the same method?

After a general search and skimming 2 wikipedia articles on Sudoku mechanics (Mathematics of Sudoku and Sudoku Algorithms), I'm still not seeing this simple approach to verifying a board as solved. All math and logic seem dedicated to solving puzzles (as in finding the correct digit for each cell) or to generating solvable puzzles. This has me thinking I am overlooking something with my math and logic, but I can't think of a board where the sum of the sets wouldn't be 1215 or a board where the sum would be 1215 and it would be an invalid board.

I am ready to be shown the err of my ways, but it would be cool to confirm that a board can be solved without confirmation that each cell value is valid.

Best Answer

Apropos your comment,

I'm guessing... that there is not an arithmetic way to check for set uniqueness?

there actually is a way, using only arithmetic, to check whether a sequence of nine numbers each between $1$ and $9$ contains all unique elements: for each number $n$ in the sequence, replace it with $2^{n-1}$, then add them all up and check that the sum is $511$. For example, the row $[5 | 3 | 4 | 6 | 7 | 8 | 9 | 1 | 2]$ is valid because $$2^{5-1} + 2^{3-1} + 2^{4-1} + 2^{6-1} + 2^{7-1} + 2^{8-1} + 2^{9-1} + 2^{1-1} + 2^{2-1} \\ = 16 + 4 + 8 + 32 + 64 + 128 + 256 + 1 + 2 \\ = 511,$$ but $[5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5]$ is not because $$2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} + 2^{5-1} \\ = 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 + 16 \\ = 144 \ne 511.$$

It should be clear that any permutation of the same set of numbers should give the same sum, so any valid solution should have the sum $511$. What is not immediately obvious is that no other sequence of nine numbers can give this sum. This is true because the Hamming weight of $511$ is $9$. The sum of $N$ numbers that are powers of $2$ can have Hamming weight at most $N$, and if there are duplicates among them, the weight of the sum is strictly less than $N$. So the only way to get a Hamming weight of $9$ by adding nine powers of $2$ is if they are all distinct.

Related Question