Hi. Everyone.Edit: 15/11/2018.
I closed this topic, because as it stands, this topic doesn't encourage more discussion/participation.
I am going to open a topic like "Solving Sudoku with Python and Calc Add-in" that can probably attract more discussions
as experienced people would come forward and give me advice when I get stuck in my journey of learning a new language.
I have invented a new [number system] to solve the Sudoku puzzles.
As I was looking at the worksheet solution of Sudoku posted by Villeroy, while I didn't study the solution in details, or even understand the solution fully, I was intrigued by the author's use of binary numbers, and a row of 11111111 at some places, without really understanding what it stands for.
An idea came to my mind. I can design a new [number system] just to tackle the [pencil and paper] method of solving the Sudoku.
The [number system] to be used is 1 is represented by 000000001, 2 is 000000010, 3 is 000000100 and so on until 9 is 100000000.
To find a solution for a single cell, we look at all the numbers already present in the row, column, and 3x3 block that contains the empty cell. Then we add up all the found numbers in the new representation. If there is a solution, the result of the sum is 7 different numbers, represented by a series of 7 (1's), and 2 of another distinct number, and a 0, in the place of the missing number.
In the following example, looking at cell H4, in the row, we find numbers 2,8,4,6; in the column: 3,7,9; and in the block 7,1,6. Adding all of them up yields the result: 111201111. This means there 2 of 6's, 1 of every other number, and 0 of 5. So 5 is the solution, 10000 in my [number system]
The operation takes care of Step 1: Looking for [naked single] in a cell from the respective row, column, and block.
Step 2 involves in finding the plausible values (the missing values) for each cell in a row, add up all values in the row, and see which number is 1. Then that is what others call the [hidden single].
To perform step 2, first the result for each cell in a row like the Step 1. Then turn any digit greater than 1 into 1. For example, 11201111 becomes 111101111 and then subtract 11101111 from 111111111 and the result is 10000, being the possible value for that cell. Do this for every cell in a row, and then add up the results of all the cells in the row. If there is a 1 in the grand total, then that 1 follow by the trailing 0 to the right is the [hidden single].
It sounds complicated in verbal explanation, but can be done with some macro functions.
To check whether a result is a single digit, and hence a solution for the cell, we can use a [function] like REPLACE(CStr(sum), “0”, “”) = 1.
To check for doubles, Cstr(sum of singles in a row) has at least 1 digit > 1
If number of singles = 81 and number of duplicates = 0, then then the puzzle is solved.
With these Step 1 and Step 2 repeated over and over, simple Sudoku puzzles can be completely solved.
I haven't got around to apply this [number system] to the next step of choosing one digit from a double digit entry in a cell in the later part of the game when applying the first 2 steps are inadequate.
I am not saying this [number system] is easy to use or better than the one I am having now, It is just that I feel excited to have [invented] a new [number system] to solve the old problem, even using the old method.
A sample of Sudoku game
<------------------Columns-------------------------------------->
Rows A B C D E F G H I
1 0 0 9 0 0 7 4 0 0
2 0 0 0 0 0 0 0 3 2
3 0 8 0 3 0 0 0 0 0
4 0 2 0 8 4 0 0 0 6
5 8 0 0 0 0 0 0 0 1
6 9 0 0 0 1 5 0 7 0
7 0 0 0 0 0 6 0 9 0
8 5 1 0 0 0 0 0 0 0
9 0 0 4 2 0 0 5 0 0
Look at cell H4
row 2,8,4,6
col 3,7,9
blk 7,1,6
1 is represented by: 000000001 Number of 1= 1 000000001
2 is represented by: 000000010 Number of 2= 1 000000010
3 is represented by: 000000100 Number of 3= 1 000000100
4 is represented by: 000001000 Number of 4= 1 000001000
5 is represented by: 000010000 Number of 5= 0 000000000
6 is represented by: 000100000 Number of 6= 2 000200000
7 is represented by: 001000000 Number of 7= 1 001000000
8 is represented by: 010000000 Number of 8= 1 010000000
9 is represented by: 100000000 Number of 9= 1 100000000
Sum → 111201111
Solution for H4 is 5, or 10000
By the way, while I have gone through the solution conceptually in my mind, I have not actually implemented the solution with any macros, because I am embarking on learning Javascript from scratch.
For those of you who are also interested in finding a solver for Sudoku, you can try to use this [number system] to create your own solution to whatever Sudoku puzzles you have.
Please share with us how you find this number system.