Author Topic: SUDOKU Challenge  (Read 11888 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: SUDOKU Challenge
« Reply #15 on: October 27, 2017, 02:40:19 PM »
Hello everyone

Here is my solution. It is very slow, but it can solve even the allegedly hardest sudoku 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.
...
That is slick  8)

Code - Auto/Visual Lisp: [Select]
  1. (sudoku '((8 nil nil nil nil nil nil nil nil)
  2.           (nil nil 3 6 nil nil nil nil nil)
  3.           (nil 7 nil nil 9 nil 2 nil nil)
  4.           (nil 5 nil nil nil 7 nil nil nil)
  5.           (nil nil nil nil 4 5 7 nil nil)
  6.           (nil nil nil 1 nil nil nil 3 nil)
  7.           (nil nil 1 nil nil nil nil 6 8)
  8.           (nil nil 8 5 nil nil nil 1 nil)
  9.           (nil 9 nil nil nil nil nil nil nil)
  10.          )
  11. )
  12. ;;< Elapsed time: 5.968000 seconds. >
  13. ;;; 8 1 2 | 7 5 3 | 6 4 9
  14. ;;; 9 4 3 | 6 8 2 | 1 7 5
  15. ;;; 6 7 5 | 4 9 1 | 2 8 3
  16. ;;; ---------------------
  17. ;;; 1 5 4 | 2 3 7 | 8 9 6
  18. ;;; 3 6 9 | 8 4 5 | 7 2 1
  19. ;;; 2 8 7 | 1 6 9 | 5 3 4
  20. ;;; ---------------------
  21. ;;; 5 2 1 | 9 7 4 | 3 6 8
  22. ;;; 4 3 8 | 5 2 6 | 9 1 7
  23. ;;; 7 9 6 | 3 1 8 | 4 5 2
  24.  
  25.  
  26. (sudoku '((nil nil 2 nil nil 9 1 nil nil)
  27.           (nil nil nil 8 3 6 nil 7 nil)
  28.           (nil nil nil nil nil nil nil 8 nil)
  29.           (nil nil 1 nil nil nil 2 4 nil)
  30.           (3 nil nil 6 5 4 nil nil 7)
  31.           (nil 7 9 nil nil nil 6 nil nil)
  32.           (nil 5 nil nil nil nil nil nil nil)
  33.           (nil 3 nil 4 1 5 nil nil nil)
  34.           (nil nil 4 2 nil nil 3 nil nil)
  35.          )
  36. )
  37. ;;< Elapsed time: 0.453000 seconds. >
  38. ;;; 7 8 2 | 5 4 9 | 1 6 3
  39. ;;; 9 1 5 | 8 3 6 | 4 7 2
  40. ;;; 6 4 3 | 7 2 1 | 5 8 9
  41. ;;; ---------------------
  42. ;;; 5 6 1 | 9 7 3 | 2 4 8
  43. ;;; 3 2 8 | 6 5 4 | 9 1 7
  44. ;;; 4 7 9 | 1 8 2 | 6 3 5
  45. ;;; ---------------------
  46. ;;; 1 5 6 | 3 9 8 | 7 2 4
  47. ;;; 2 3 7 | 4 1 5 | 8 9 6
  48. ;;; 8 9 4 | 2 6 7 | 3 5 1
« Last Edit: October 27, 2017, 03:18:12 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: SUDOKU Challenge
« Reply #16 on: November 02, 2017, 06:18:51 PM »
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.

Here it is (better to be late than never) :

Code - Auto/Visual Lisp: [Select]
  1. ; https://www.theswamp.org/index.php?topic=53547.0
  2. (defun PlaySudoku ( aL / _MatrixSubstNth PlaySudoku:IsSudokuValid txt2num *error* dcl des dch dcf deferrmsg nL row col kL rL )
  3.   '(87 114 105 116 116 101 110 32 98 121 32 71 114 114 114)
  4.   ; _$ (_MatrixSubstNth '(1 2) "K" '(("A" "B" "C")("D" "E" "F")("G" "H" "I"))) -> (("A" "B" "C") ("D" "E" "K") ("G" "H" "I"))
  5.   ; _$ (_MatrixSubstNth '(1 8) "K" '(("A" "B" "C")("D" "E" "F")("G" "H" "I"))) -> (("A" "B" "C") ("D" "E" "F") ("G" "H" "I"))
  6.   (defun _MatrixSubstNth ( NthL NewItm aL / r c )
  7.     (setq r -1) (mapcar (function (lambda (row) (setq r (1+ r)) (setq c -1) (mapcar (function (lambda (itm) (setq c (1+ c)) (if (equal (list r c) NthL 1e-1) NewItm itm))) row))) aL)
  8.   ); defun _MatrixSubstNth
  9.  
  10.   (defun PlaySudoku:IsSudokuValid ( aL / InvalidAt GroupByN ValidRowColp cols tmpL r )
  11.    
  12.     ; _$ (InvalidAt '(lambda (a) (= a 5)) '(lambda (a b) (print (strcat "Error at item n."  b " :\n" (vl-prin1-to-string a)))) '(1 2 3 4 5 6 7 8 9)) -> "Error at item n.1 :\n1" T
  13.     ; _$ (InvalidAt '(lambda (a) (/= a 5)) '(lambda (a b) (print (strcat "Error at item n."  b " :\n" (vl-prin1-to-string a)))) '(1 2 3 4 5 6 7 8 9)) -> "Error at item n.5 :\n5" T
  14.     ; _$ (InvalidAt '(lambda (a) (/= a 15)) '(lambda (a b) (print (strcat "Error at item n."  b " :\n" (vl-prin1-to-string a)))) '(1 2 3 4 5 6 7 8 9)) -> nil
  15.     (setq InvalidAt
  16.       (lambda ( f mf L / i )
  17.         (setq i 0) (setq f (eval f)) (setq mf (eval mf))
  18.         (vl-some (function (lambda (x) (setq i (1+ i)) (if (not (f x)) (progn (mf x (itoa i)) T)))) L)
  19.       )
  20.     ); setq InvalidAt
  21.    
  22.     (defun GroupByN ( n L / r )
  23.       (repeat n (and L (setq r (cons (car L) r))) (setq L (cdr L)) r)
  24.       (if L (cons (reverse r) (GroupByN n L)) (list (reverse r)))
  25.     ); defun GroupByN
  26.    
  27.     ; _$ (ValidRowColp '(1 2 3 6 5 4 7 8 9)) -> T
  28.     ; _$ (ValidRowColp '(1 2 3 6 9 4 7 8 9)) -> nil
  29.     (defun ValidRowColp ( L / nL )
  30.       (setq nL '(1 2 3 4 5 6 7 8 9))
  31.       (vl-every (function (lambda (x) (if (member x nL) (progn (setq nL (vl-remove x nL)) T)))) L)
  32.     ); defun ValidRowColp
  33.    
  34.     (cond
  35.       ( (not (vl-consp aL)) (prompt "\n#1. Not vl-consp.") )
  36.       ( (/= 9 (length aL)) (prompt "\n#2. Invalid length.") )
  37.       ( (InvalidAt '(lambda (x) (and (vl-consp x) (= 9 (length x)))) '(lambda (a b) (print (strcat "\nError[basic] at row n." b " :\n" (vl-prin1-to-string a)))) aL) )
  38.       ; ( (InvalidAt '(lambda (x) (and (eq 'INT (type x)) (<= 1 x 9))) '(lambda (a b) (print (strcat "\nError at atom n." b " :\n" (vl-prin1-to-string a)))) (apply 'append aL)) )
  39.       ( (progn (setq cols (apply 'mapcar (cons 'list aL))) nil) )
  40.       ( (InvalidAt 'ValidRowColp '(lambda (a b) (set_tile "error" (strcat "*Error at row n." b " : " (vl-prin1-to-string a) "*"))) aL) )
  41.       ( (InvalidAt 'ValidRowColp '(lambda (a b) (set_tile "error" (strcat "*Error at col n." b " : " (vl-prin1-to-string a) "*"))) cols) )
  42.       (
  43.         (and (setq tmpL (mapcar (function (lambda (x) (GroupByN 3 x))) aL))
  44.           (not
  45.             (InvalidAt '(lambda (x) (ValidRowColp (apply 'append x))) '(lambda (a b) (set_tile "error" (strcat "Error at sector n." b " : " (vl-prin1-to-string a) "*")))
  46.               (append ; Check 3x3 Matrix Sublists
  47.                 (GroupByN 3 (mapcar 'car tmpL))
  48.                 (GroupByN 3 (mapcar 'cadr tmpL))
  49.                 (GroupByN 3 (mapcar 'caddr tmpL))
  50.               ); append
  51.             )
  52.           )
  53.           (setq r T)
  54.         ); progn
  55.       )
  56.     ); cond
  57.     r
  58.   ); defun IsSudokuValid
  59.  
  60.   (setq txt2num (lambda ( txt / num ) (if (and txt (numberp (setq num (vl-some '(lambda (x) (distof txt x)) (list (getvar 'lunits) 1 2 3 4 5))))) num)))
  61.  
  62.   (defun *error* ( msg )
  63.     (and (< 0 dch) (unload_dialog dch))
  64.     (and (eq 'FILE (type des)) (close des))
  65.     (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl))
  66.     (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) ))
  67.     (princ)
  68.   ); defun *error*
  69.  
  70.   (cond
  71.     ( (not (vl-consp aL)) (princ "\nInvalid input - aL is not a list.") )
  72.     ( (or (/= 9 (length aL)) (not (vl-every '(lambda (x) (and (vl-consp x) (= 9 (length x)) (vl-every '(lambda (i) (or (not i) (eq 'INT (type i)))) x))) aL)))
  73.       (princ "\nInvalid list, the format must be 9x9 assoc list of integers and nils")
  74.     )
  75.     ( (progn (setq nL (apply 'mapcar (cons 'list aL))) nil) ) ; Thats right, I'll write it with column-mode, cause of aligning issues
  76.     (
  77.       (not
  78.         (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w"))
  79.           (mapcar (function (lambda (x) (princ (strcat "\n" x) des)))
  80.             (list
  81.               "PlaySudoku : dialog"
  82.               "{ label = \"Sudoku\"; children_alignment = centered; spacer;"
  83.               (strcat
  84.                 "\n: row"
  85.                 "{"
  86.                 (apply 'strcat
  87.                   (progn (setq col -1)
  88.                     (mapcar
  89.                       (function
  90.                         (lambda ( _col ) (setq col (1+ col))
  91.                           (strcat
  92.                             "\n: column"
  93.                             "\n{ children_fixed_width = true; children_alignment = centered; "
  94.                             (apply 'strcat
  95.                               (progn (setq row -1)
  96.                                 (mapcar
  97.                                   (function
  98.                                     (lambda ( x / k ) (setq row (1+ row))
  99.                                       (setq k (apply 'strcat (mapcar 'itoa (list row col))))
  100.                                       (setq kL (cons k kL))
  101.                                       (cond
  102.                                         ( (null x)
  103.                                           (strcat
  104.                                             "\n: edit_box { key = \"" k "\"; alignment = centered; edit_width = 3; }"
  105.                                           ); strcat
  106.                                         ) ; (null x)
  107.                                         ( (eq 'INT (type x))
  108.                                           (strcat
  109.                                             "\n: edit_box { value = \"" (strcat "   " (itoa x)) "\"; key = \"" k "\"; alignment = centered; edit_width = 3; is_enabled = false; }"
  110.                                             ; "\n: button { label = \"" (itoa x) "\"; key = \"" k "\"; width = 1; height = 1; is_enabled = true; }"  ; button tile just can't align properly along with the edit_box
  111.                                           ); strcat
  112.                                         )
  113.                                       ); cond
  114.                                     ); lambda (x)
  115.                                   )
  116.                                   _col
  117.                                 ); mapcar
  118.                               ); progn
  119.                             ); apply 'strcat
  120.                             "\n}"
  121.                           ); strcat
  122.                         ); lambda ( _col )
  123.                       ); function
  124.                       nL
  125.                     ); mapcar
  126.                   ); progn
  127.                 ); apply 'strcat
  128.                 "}"
  129.               ); strcat
  130.               (strcat "  spacer; ok_cancel; : text { label = \"" (setq deferrmsg ">> Solve this Sudoku / Use [TAB] and [1-9] keys <<") "\"; key = \"error\"; }") ; deferrmsg = default error message
  131.               "}"
  132.             ); list
  133.           ); mapcar
  134.           (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl)))
  135.         ); and
  136.       ); not
  137.       (princ "\nUnable to write or load the DCL file.")
  138.     )
  139.     ( (not (new_dialog "PlaySudoku" dch)) (princ "\nUnable to display the dialog") )
  140.     (
  141.       (progn
  142.         (setq kL (reverse kL)) ; zero-based matrix string list: "00", "01" ... "88"
  143.         (mapcar (function (lambda (x) (client_data_tile x (get_tile x)))) kL)
  144.         (setq rL (mapcar 'cons kL (mapcar 'get_tile kL))) ; initially set the return list
  145.         (mapcar
  146.           (function
  147.             (lambda (x)
  148.               (action_tile x
  149.                 (vl-prin1-to-string
  150.                   (quote
  151.                     (
  152.                       (lambda ( / v r c )
  153.                         (mapcar (function (lambda (xx / vi vs) (and (setq vi (txt2num (setq vs (get_tile xx)))) (<= 1 vi 9) (set_tile xx (strcat "   " (itoa (read vs))))))) kL) ; acts like an reactor - prety cool, huh?
  154.                         (set_tile "error" deferrmsg)
  155.                         (mapcar 'set '(r c) (mapcar 'itoa (mapcar '1+ (mapcar 'read (mapcar 'chr (vl-string->list $key))))))
  156.                         (cond
  157.                           ( (= $data $value) )
  158.                           ( (and (setq v (txt2num $value)) (<= 1 v 9))
  159.                             (client_data_tile $key $value)
  160.                             (setq rL (subst (cons $key $value) (assoc $key rL) rL))
  161.                           )
  162.                           ( (progn (set_tile $key $data) (set_tile "error" (strcat "*Error: Invalid input at tile [" r "-" c "].*")) (mode_tile $key 2)) )
  163.                         ); cond
  164.                         ; (setq keys (subst (cons $key $data) (assoc $key keys) keys)) ; QUOTE/apostrophe ruins the 'strcase' status
  165.                       ); lambda ( / v )
  166.                     )
  167.                   ); quote
  168.                 ); vl-prin1-to-string
  169.               ); action_tile x
  170.             ); lambda
  171.           ); function
  172.           kL
  173.         ); mapcar
  174.         (action_tile "accept"
  175.           (vl-prin1-to-string
  176.             '(
  177.               (lambda nil
  178.                 (mapcar
  179.                   (function
  180.                     (lambda (x / k kx ky v ) ; _$ (substr "ab" 1 1) -> "a" ; _$ (substr "ab" 2 2) -> "b"
  181.                       (setq k (car x))
  182.                       (setq kx (atoi (substr k 1 1)))
  183.                       (setq ky (atoi (substr k 2 2)))
  184.                       (setq v (read (cdr x)))
  185.                       (setq aL (_MatrixSubstNth (list kx ky) v aL))
  186.                     )
  187.                   )
  188.                   rL
  189.                 ); mapcar
  190.                 (cond
  191.                   ; ( (not (IsSudokuValid aL)) (set_tile "error" "*** Error: Invalid sudoku! ***") )
  192.                   (
  193.                     (vl-some
  194.                       (function
  195.                         (lambda (x / a b v r c )
  196.                           (setq a (car x)) (setq b (cdr x)) (setq v (read b))
  197.                           (cond
  198.                             ( (and (eq 'INT (type v)) (<= 1 v 9)) nil)
  199.                             (
  200.                               (progn
  201.                                 (mapcar 'set '(r c) (mapcar 'itoa (mapcar '1+ (mapcar 'read (mapcar 'chr (vl-string->list a))))))
  202.                                 (set_tile "error" (strcat "*Error, empty item at Row: " r ", Column: " c "*"))
  203.                                 (mode_tile a 2) T
  204.                               ); progn
  205.                             )
  206.                             ; ( (progn (set_tile "error" (strcat "*** Error: Invalid item: " a "! ***")) (mode_tile a 3) T) )
  207.                           ); cond
  208.                         ); lambda
  209.                       ); function
  210.                       rL
  211.                     ); vl-some
  212.                   )
  213.                   ( (not (PlaySudoku:IsSudokuValid aL))  )
  214.                   ( (done_dialog 1) )
  215.                 ); cond
  216.               ); lambda ( L )
  217.             )
  218.           )
  219.         ); action_tile "accept"
  220.         (/= 1 (setq dcf (start_dialog)))
  221.       ); progn
  222.       (princ "\nUser cancelled the dialog.")
  223.     )
  224.     ( (progn (alert "You won! Next time I'll put some picture here.") T) )
  225.   ); cond
  226.   (*error* nil) (princ) aL
  227. ); defun PlaySudoku

Example:
Code: [Select]
(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)
)

The dialog is based on a technique I demonstrated here.
And I'm still thankful to Lee Mac for tutoring me on DCL and other different LISP stuff.

BTW I thought about including "I'm giving up" button - that solves the sudoku, by using a subfunction like Stefan's. But at this point I'm leaving the routine like this.




(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: SUDOKU Challenge
« Reply #17 on: November 03, 2017, 06:38:20 AM »
Thanks Grrr, you saved us from typing boring DCL... Nice usage of your subs, btw... Now I shell start torturing people with the hardest one posted by Stefan...
 :evil:
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: SUDOKU Challenge
« Reply #18 on: November 03, 2017, 08:26:17 AM »
Thanks Marko, I rather find DCL very interesting :)

BTW I think it would be handy if someone wrote an UnSolvedSudokuGenerator routine, that will return a sudoku list (like in our inputs) to be solved.
The only way I could figure out to start with is this:

Code - Auto/Visual Lisp: [Select]
  1. ; note: 'x' stands for nil symbol (I used it for a better readability)
  2. (foo n)
  3. ->
  4. '( ; argument 'n' will fill for each Sector n amounth of random [1-9] items
  5.   (x x x  x x x  x x x)
  6.   (x x x  x x x  x x x)
  7.   (x x x  x x x  x x x)
  8.  
  9.   (x x x  x x x  x x x)
  10.   (x x x  x x x  x x x)
  11.   (x x x  x x x  x x x)
  12.  
  13.   (x x x  x x x  x x x)
  14.   (x x x  x x x  x x x)
  15.   (x x x  x x x  x x x)
  16. )
  17.  
  18. ; Examples:
  19. (foo 1) -> ; Hard/Impossible ?
  20. '( ; argument 'n' will fill for each Sector n amounth of random [1-9] items
  21.   (1 x x  x x x  x x x)
  22.   (x x x  x 3 x  x x 7)
  23.   (x x x  x x x  x x x)
  24.  
  25.   (x x x  4 x x  x x x)
  26.   (x 3 x  x x x  x x x)
  27.   (x x x  x x x  x x 2)
  28.  
  29.   (x x x  x x x  x 5 x)
  30.   (2 x x  6 x x  x x x)
  31.   (x x x  x x x  x x x)
  32. )
  33.  
  34. (foo 2) -> ; Medium/Hard ?
  35. '( ; argument 'n' will fill for each Sector n amounth of random [1-9] items
  36.   (x 2 x  x x 5  x x x)
  37.   (3 x x  x x x  x x x)
  38.   (x x x  4 x x  1 5 x)
  39.  
  40.   (x x 6  x x 3  x x 1)
  41.   (x 1 x  x 7 x  x x x)
  42.   (x x x  x x x  9 x x)
  43.  
  44.   (x x x  2 x x  x x 7)
  45.   (x x 2  x x 1  x x x)
  46.   (x 6 x  x x x  x 8 x)
  47. )
  48.  
  49. (foo 3) -> ; Easy/Medium
  50. '( ; argument 'n' will fill for each Sector n amounth of random [1-9] items
  51.   (x 2 x  x x 5  x 4 x)
  52.   (3 x x  x 1 x  x x x)
  53.   (x x 4  4 x x  1 5 x)
  54.  
  55.   (x x 6  x x 3  x x 1)
  56.   (x 1 x  x 7 x  x x x)
  57.   (5 x x  8 x x  9 x 4)
  58.  
  59.   (1 x x  2 x x  2 x 7)
  60.   (x x 2  x x 1  x x x)
  61.   (x 6 x  x 3 x  x 8 x)
  62. )

To split the above task, maybe just generate a different (1 2 3 4 5 6 7 8 9) lists, say given 'n = 3', generate list with random [1-9] numbers on random positions of the list.
Say 9 list outputs like: (nil nil 2 nil 9 nil 6 nil nil) merged into assoc list.
Then use Lee's bar subfunction he posted in Reply #10 to re-assemble the whole list.
Might be required IsUnSolvedSudokuValid function.
Ofcourse before giving any return, must make sure generator's output to be valid/solvable, hence should be wrapped within a loop and tested if the sudoku is solvable(with a routine like Stefan's).

I know my idea doesn't cover all types unsolved sudoku generators, since 'n' amount is not fixed always for the sectors, but would be a good start.


:idea: Then, the future ideas for the DCL work would be:

Initial Dialog Prompt with Buttons (choose difficulty):
[Easy/Medium]
[Medium/Hard]
[Hard/Impossible]

And after all this, the top of the cake would be to make it competitive, where each user collects points for different solved sudoku.
+ wrapping all posted suggestions in this thread will make the overall code better (like including buttons [I'm giving up, show answer] ).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: SUDOKU Challenge
« Reply #19 on: November 07, 2017, 07:26:49 PM »
Here it is (better to be late than never)

Nice DCL Grrr1337 - how about we add some gridlines  :-)




Grrr1337

  • Swamp Rat
  • Posts: 812
Re: SUDOKU Challenge
« Reply #20 on: November 08, 2017, 11:07:31 AM »
Here it is (better to be late than never)

Nice DCL Grrr1337 - how about we add some gridlines  :-)


Thanks, Lee!
Your dialog looks prettier, so I shall rewrite that code, using your suggestion..
Most importantly for me is that I could learn some new stuff from your code, like the custom predefined tiles and using the dialog's key to set a label - so thanks for sharing!  :-D

BTW I think it would look even better with outer borders, but I'm not good with using/visualising the vector_image funciton, so heres something I can be a shame of  :nerdyembarassed: :...


(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

pBe

  • Bull Frog
  • Posts: 402
Re: SUDOKU Challenge
« Reply #21 on: November 08, 2017, 11:48:40 AM »
excellent codes everyone :)






Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: SUDOKU Challenge
« Reply #22 on: November 09, 2017, 10:30:26 AM »

That is slick  8)

Code - Auto/Visual Lisp: [Select]
  1. (sudoku '((8 nil nil nil nil nil nil nil nil)
  2.           (nil nil 3 6 nil nil nil nil nil)
  3.           (nil 7 nil nil 9 nil 2 nil nil)
  4.           (nil 5 nil nil nil 7 nil nil nil)
  5.           (nil nil nil nil 4 5 7 nil nil)
  6.           (nil nil nil 1 nil nil nil 3 nil)
  7.           (nil nil 1 nil nil nil nil 6 8)
  8.           (nil nil 8 5 nil nil nil 1 nil)
  9.           (nil 9 nil nil nil nil nil nil nil)
  10.          )
  11. )
  12. ;;< Elapsed time: 5.968000 seconds. >
  13. ...

Thanks for the test ronjonp. On my computer it takes 20sec and 700+ iterations.
I do have another version that takes only 5 sec in my computer and 161 iterations, but at a closer look, it is just by chance. For the reverse matrix, it would take 3000+ iterations and a very long time.


And this is my unfinished sudoku dialog.

ronjonp

  • Needs a day job
  • Posts: 7526
Re: SUDOKU Challenge
« Reply #23 on: November 09, 2017, 10:36:47 AM »
I compiled your code and optimized the '(lambda  to (function (lambda ...  it solved that puzzle in about 1/2 a second. Nice work  :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: SUDOKU Challenge
« Reply #24 on: November 09, 2017, 12:28:30 PM »
Great dialog Stefan - a shame that the colours invert when an image button is clicked...  :|

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: SUDOKU Challenge
« Reply #25 on: November 09, 2017, 01:05:19 PM »
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.

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: SUDOKU Challenge
« Reply #26 on: November 11, 2017, 08:57:46 AM »
New dialog.



Grrr1337

  • Swamp Rat
  • Posts: 812
Re: SUDOKU Challenge
« Reply #27 on: November 11, 2017, 09:24:29 AM »
New dialog.

Wow, this one looks insane!  :-o
Did you use standard DCL or Open/Object DCL to code it?
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: SUDOKU Challenge
« Reply #28 on: November 11, 2017, 10:05:53 AM »
Awesome work Stefan, I'm impressed.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: SUDOKU Challenge
« Reply #29 on: November 11, 2017, 10:41:16 AM »
Impressive work Stefan, kudos.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst