[Closed] I invented a [number system] to solve Sudoku puzzle

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

[Closed] I invented a [number system] to solve Sudoku puzzle

Post by OldStd »

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.
Hi. Everyone.

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.
Last edited by OldStd on Thu Nov 15, 2018 11:02 am, edited 1 time in total.
Openoffice 4.15
Windows 10
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by JeJe »

Using individual bits (or combinations of individual bits) to represent something other than parts of a number is common.

As an example, if you look at this page you can see the flag values are all powers of 2 (1,2,4,8 etc), ie individual bits. In that way 10 different values can be passed as one long variable. You're doing the same thing - setting 1 to 9 as on/off values using an individual bit for each.

https://www.openoffice.org/api/docs/com ... Flags.html
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by OldStd »

Greetings Jeje.
Thank you for your response and the link showing an example.
Looking at the topic again, I find there is nothing so great about my [invention].
I am representing 1 as 10^0, 2 as 10^1, 3 as 10^2, …., and 9 as 10^8.
Because of the resemblance of the resulting representations to the base-10 numbers, we can add them all up to see how many of each digit appears in a row, column, or 3x3 block. This happens to be useful in eliminating the digits in the row, column, 3x3 block that contain the cell under consideration. Maybe this represents another way to solve the Sudoku puzzle.
When I went back to look at the example given by Villerory, I see that it was exactly what the author was doing with his base-2 system. In fact, on close examination, the anther has done the [addition] for the rows and columns in the second blocks of columns in his solution.
In the next block of columns, with all the cell-formulae having so many uses of SUBSTITUTE, up to now, I haven't figured out what the author was trying to do, and how he derived his solution. It is quite difficult to follow the reasoning and logic of someone else, when no explanation was given.
Please refer to:
http://www.mediafire.com/file/4fmq27hhy ... 1.ods/file
In my previous discussion on using OO BASIC to solve the Sudoku, a few of the more senior members in the forum had strongly advised that I use something other than OO BASIC to solve the Sudoku, so I am putting aside the current line of thinking for a while and try to learn up Javascript in the meantime, and see if I can come up with a different solution to the Sudoku puzzle.
Just to indicate to you that I mean no offense to anyone and you in particular, after you have read my response, I am going to delete this topic from the forum so that it won't waste the time of the other readers as well.
Thanks and regards.
Openoffice 4.15
Windows 10
JeJe
Volunteer
Posts: 2784
Joined: Wed Mar 09, 2016 2:40 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by JeJe »

Good luck with Javascript. According to this, its the best one to learn...

https://www.fullstackacademy.com/blog/n ... learn-2018
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: I invented a [number system] to solve the Sudoku puzzles

Post by RoryOF »

The various sequence structures of Python - lists, tuples, strings - might lend themselves to an elegant version of your method.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by OldStd »

Postby JeJe » Thu Nov 08, 2018 11:43 pm

Good luck with Javascript. According to this, its the best one to learn...

https://www.fullstackacademy.com/blog/n ... learn-2018
Thanks. JeJe, for your link. It is interesting to note that Javascript is the most popular for a number of years in a row.
I choose to learn Javascript now because I am more familiar with procedural programming for the time being.
Openoffice 4.15
Windows 10
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by OldStd »

RoryOF wrote:The various sequence structures of Python - lists, tuples, strings - might lend themselves to an elegant version of your method.
Thanks, RoryOF, for your suggestion.
I choose to learn Javascript first now because I am more familiar with procedural programming.
Edit: 15/11/2018. I read elsewhere subsequently, that Javascript is not for procedural programming, but Python is. I am now starting to learn Python instead.

I have just downloaded and installed LibreOffice today for the first time as I only heard of this in this forum recently.
Apparently, we can write macros in Javascript or Python and run the macros in LibreOffice. I don't know how to do this at present. Eventually, I'll get to learn Python programming as well. I had completed an introductory course in Python a couple of years ago. But for lack of practice, I have forgotten most of it and have to revise even the most basic.
Last edited by OldStd on Thu Nov 15, 2018 10:53 am, edited 1 time in total.
Openoffice 4.15
Windows 10
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by OldStd »

OldStd wrote:Greetings Jeje.
...
Just to indicate to you that I mean no offense to anyone and you in particular, after you have read my response, I am going to delete this topic from the forum so that it won't waste the time of the other readers as well.
I see that there are some readers following this discussion. Some may find this new approach to solving the Sudoku interesting, and so I am just going to let the topic stay for a while.

I may come back to provide some basic codes to [prime the pump], so to say, for the beginners. It may be Javascript, or Python, depending on what I have learned in the near future, that may be running in LibreOffice.
Openoffice 4.15
Windows 10
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: I invented a [number system] to solve the Sudoku puzzles

Post by RoryOF »

Please note that we do not advocate deletion of topics on the Forum; there is often useful information in such topics that may be helpful for others.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
OldStd
Posts: 116
Joined: Tue Sep 11, 2018 8:46 pm

Re: I invented a [number system] to solve the Sudoku puzzles

Post by OldStd »

RoryOF wrote:Please note that we do not advocate deletion of topics on the Forum; there is often useful information in such topics that may be helpful for others.
Greetings. RoryOF.
Your comments noted.
I won't talk about [deleting] the topic any further.
I may come back to see if I can further contribute to the topic after I learn up some Javascript, and later, after learning some more Python, as a way to apply what I have newly learned.
Thanks and regards.
Openoffice 4.15
Windows 10
Post Reply