For 1 -> S To 8
S = 3 Or S = 6 => Isz S
3 + 3Int S⌟3 -> Q
9 -> Dim List 1
For 1 -> X To 9
Mat A[S, X -> N
List 1[N -> U
If U :Then
If S > X :Then
X -> V : X -> R
Else
1 + 3Int X⌟3.5 -> R
If S > R :Then
S -> V
Else
R -> V
IfEnd
Isz R : Isz R
IfEnd
For V -> V To R
For S + 1 -> W To Q
Mat A[W, V
If 0 = List 1[Ans :Then
N -> Mat A[W, V
Text 6W, 6V, N
Ans -> Mat A[S, X
Text 6S, 6X, Ans
X -> List 1[Ans
Goto 1
IfEnd
Next
Next
X -> List 1[N
Do
U -> V : S -> W : Isz W
Mat A[W, V
If Q != W And List 1[Ans :Then
Isz W
Mat A[W, V
IfEnd
Ans -> Mat A[S, V
Text 6S, 6V, Ans
N -> Mat A[W, V
Text 6W, 6V, N
List 1[Ans -> U
V -> List 1[Ans
Ans -> N
LpWhile U
Else
X -> List 1[N
IfEnd
Lbl 1
Next
9 -> Dim List 1
For 1 -> Y To 9
Mat A[Y, S -> N
List 1[N -> U
If U :Then
If S >= Y :Then
Y -> W : Y -> R
Else
3Int Y⌟3.5 -> R
Isz R
If S >= R :Then
S -> W : Isz W
Else
R -> W
IfEnd
Isz R : Isz R
IfEnd
For W -> W To R
For S + 1 -> V To Q
Mat A[W, V
If 0 = List 1[Ans :Then
N -> Mat A[W, V
Text 6W, 6V, N
Ans -> Mat A[Y, S
Text 6Y, 6S, Ans
Y -> List 1[Ans
Goto 2
IfEnd
Next
Next
N -> T
Y -> List 1[N
Do
U -> W : S -> V : Isz V
Mat A[W, V
If (Y != W Or N != T) And Q != V And List 1[Ans :Then
Isz V
Mat A[W, V
IfEnd
Ans -> Mat A[W, S
Text 6W, 6S, Ans
N -> Mat A[W, V
Text 6W, 6V, N
List 1[Ans -> U
W -> List 1[Ans
Ans -> N
LpWhile U
Else
Y -> List 1[N
IfEnd
Lbl 2
Next
Next
This sorts the 9x9 matrix so its a valid sudoku grid (numbers 1-9 in every row, column and 3x3 square)
Starts at the top left corner and starts sorting the top row, left to right
Then does the 1st column, 2nd row etc
It goes across the row, making a list of all the numbers
If it finds a duplicate, it tries to swap it with a non-duplicate number within the same 3x3 square
If it cant, it goes back to the previous location of the duplicate number and force swaps it with the number below it
If that number is a duplicate, it will go to the location of that number
It will keep going back until it finds a non-duplicate number
Here is a video and doc explaining it a bit better
https://youtu.be/LHCHH5siBCg
Download doc
Citer : Posté le 05/09/2019 13:23 | #
Enverything in Basic Casio ? Wow dude, you are a genius ! But it's not fast to make an engine to move the cursor, it isn't ?
Citer : Posté le 05/09/2019 21:07 | #
Currently theres only a generator and solver
The slow part is drawing to the screen, but ofc I wont do that when its fininshed as it would show the player the solved sudoku
The generator and solver can still be speed up, it doesn't take the best path is solving it right now
When playing a sudoku
The user will have higher prioity, but only when they are not doing anything, the generator/solver program will have a small amount of time to calculate part of the sudoku
It will give time back to the player, if the player isn't doing anything it will go back to the solver
As long as the time that the solver uses is small enough (but not too small), the game shouldn't be too slow :P
Citer : Posté le 06/09/2019 02:40 | #
@Redcmd
It ’s a great program.
It works well in C.Basic.
To work in the 90+E high resolution screen,
Since the width of the space is small, it works well by adding one more space. .
Overclocking utilitaire Ftune/Ptune2/Ptune3 est également disponible.
Si vous avez des questions ou un rapport de bogue, n'hésitez pas à me le faire savoir.
Citer : Posté le 06/09/2019 02:41 | #
Still got a long way to go
Its currently massivey unoptimized, but I will slowly get there :P
Would take soo long to test without C.Basic
Citer : Posté le 06/09/2019 09:59 | #
Can we get some information about the time spend by each function in order to generate/solve a grid ?
Citer : Posté le 08/09/2019 05:40 | #
Thats a tricky question
Generatoring then solving a grid takes about a minute
if you dont draw anything to the screen, apart from the final grid (because draw commands are super slow)
But the final outcome might not be a genuine grid, only because theres not a 100% chance that the grid has only one solution
So it could take multiple goes, before getting a genuine grid
Then theres the problem of grading the grid: easy, medium and hard
After a grid is solved, more places a removed, then its resolved to test if its still possiblt to solve via human techniques
This will take the longest
up to a max of 30min!
but Im expecting less than 10min
Citer : Posté le 08/09/2019 09:51 | #
That a great algorithm then
I've used one on a PC with python that used brute force (kinda) to solve grids and it always tooks hours
Citer : Posté le 08/09/2019 09:56 | #
On of the best algorithms (to the extent of my knowledge) to solve this kind of combinatorial problems is the dancing links. It's absurdly elegant and can be used whenever the problem looks like set covering and backtracking
I guess it is not very suitable for calculators though, except in its array form. xD
Citer : Posté le 08/09/2019 10:56 | #
Im also wondering on how to grade the grids
The most common way is to play the sudoku like a human player and give different amounts of points towards different techniques used: Single Candidate, Single Position etc
no algorithm is go for a calculator :P
they all take thousands of iterations to finish