The following should calculate the possible candidate entries for each space in the sudoku -
The following should calculate the possible candidate entries for each space in the sudoku -This has to be the one of the most complex functions I've seen from you, insane job!
BTW Maybe use 'x' symbol instead of nil, so it would take up space for only 1 character for a better visual formatting:Code - Auto/Visual Lisp: [Select]
(sudoku '( (x x 4 8 x x x 1 7) (6 7 x 9 x x x x x) (5 x 8 x 3 x x x 4) (3 x x 7 4 x 1 x x) (x 6 9 x x x 7 8 x) (x x 1 x 6 9 x x 5) (1 x x x 8 x 3 x 6) (x x x x x 6 x 9 1) (2 4 x x x 1 5 x x) ) )
'x' is not assigned and would mean that x = nil.
_$ (= nil 'x)
nil
Careful - the unevaluated symbol 'x' will not equal nil...Code: [Select]_$ (= nil 'x)
nil
Nice one Grrr1337 :-)
FWIW, here's another way to write the 'ValidRowColp' function:Code - Auto/Visual Lisp: [Select]
(mapcar '(lambda ( n ) (nth n l)) (vl-sort-i l '<))
rather than:(vl-sort l '<)
because now I think that the simpliest way to write it would be:(defun validrowcolp ( l )
(equal (vl-sort l '<) '(1 2 3 4 5 6 7 8 9))
)
wouldn't came up with this, without your suggestion :) [since I might overthinked my version of ValidRowColp]. Just for fun, here are two more ways to group the matrix into the 3x3 submatrices, depending on the order desired:
...
I think I'm there:
...
Though, the algorithm is essentially brute-force, so for sparse inputs be prepared to wait... :wink:
Hello everyoneThat is slick 8)
Here is my solution. It is very slow, but it can solve even the allegedly hardest sudoku (http://www.telegraph.co.uk/news/science/science-news/9359579/Worlds-hardest-sudoku-can-you-crack-it.html) in the world (btw, i couldn't solve it on paper...); the grid is supposed to be fair (no conflicts in the initial grid) and solvable.
...
BTW, I have an idea about the actual game (which includes DCL) but I must have more free time to write it. :idea:
Although it doesn't include sudoku solvers - just initial list of unsolved sudoku, like the above, along with user input and IsSudokuValid checking.
(PlaySudoku
'(
(nil nil 4 8 nil nil nil 1 7 )
( 6 7 nil 9 nil nil nil nil nil)
( 5 nil 8 nil 3 nil nil nil 4 )
( 3 nil nil 7 4 nil 1 nil nil)
(nil 6 9 nil nil nil 7 8 nil)
(nil nil 1 nil 6 9 nil nil 5 )
( 1 nil nil nil 8 nil 3 nil 6 )
(nil nil nil nil nil 6 nil 9 1 )
( 2 4 nil nil nil 1 5 nil nil)
)
)
; Answer is:
(
(9 3 4 8 2 5 6 1 7)
(6 7 2 9 1 4 8 5 3)
(5 1 8 6 3 7 9 2 4)
(3 2 5 7 4 8 1 6 9)
(4 6 9 1 5 3 7 8 2)
(7 8 1 2 6 9 4 3 5)
(1 9 7 5 8 2 3 4 6)
(8 5 3 4 7 6 2 9 1)
(2 4 6 3 9 1 5 7 8)
)
Here it is (better to be late than never)
Here it is (better to be late than never)
Nice DCL Grrr1337 - how about we add some gridlines :-)
That is slick 8)Code - Auto/Visual Lisp: [Select]
(sudoku '((8 nil nil nil nil nil nil nil nil) (nil nil 3 6 nil nil nil nil nil) (nil 7 nil nil 9 nil 2 nil nil) (nil 5 nil nil nil 7 nil nil nil) (nil nil nil nil 4 5 7 nil nil) (nil nil nil 1 nil nil nil 3 nil) (nil nil 1 nil nil nil nil 6 8) (nil nil 8 5 nil nil nil 1 nil) (nil 9 nil nil nil nil nil nil nil) ) ) ;;< Elapsed time: 5.968000 seconds. > ...
Great dialog Stefan - a shame that the colours invert when an image button is clicked... :|Yes, exactly my thoughts... That's why I used 252 for the background. It's very close to its complementary color. What you see flickering is the text and the grid.
New dialog.