Skip to content

sudoku problem generator & solver for Common Lisp & McCLIM

Notifications You must be signed in to change notification settings

tortkis/sudoku-mcclim

Repository files navigation

sudoku-mcclim

Overview:

  This is a collection of sudoku generator & solver functions for
  Common Lisp:

  * sudoku.lisp ............. core functions
  * sudoku-control.lisp ..... functions for playing games
  * sudoku-ui-mcclim.lisp ... GUI for McCLIM

  The program can generate and solve any size of sudoku ((m*n)^2),
  where m and n are the number of rows and columns of a block,
  respectively, and the number of total rows/columns is m*n.

Usage:

  Starting GUI

    (asdf:oos 'asdf:load-op 'sudoku-mcclim)
    (sudoku-mcclim:run)

  If GUI is not needed, 'sudoku-control' package provides CUI for game
  playing.  'sudoku' package contains core functions.

  examples:

    (asdf:oos 'asdf:load-op 'sudoku)

    ;; This makes a valid sudoku table.

    (car (sudoku:make-multiple-sudoku-table 1 '(3 3) :random t))

    => #S(SUDOKU:STBL
          :TABLE #2A((2 9 6 5 4 7 3 8 1)
                     (5 3 4 8 6 1 7 9 2)
                     (7 8 1 2 9 3 4 5 6)
                     (4 6 8 3 7 9 2 1 5)
                     (1 5 7 6 8 2 9 4 3)
                     (9 2 3 1 5 4 8 6 7)
                     (3 4 2 9 1 6 5 7 8)
                     (6 7 5 4 2 8 1 3 9)
                     (8 1 9 7 3 5 6 2 4))
          :NR 3
          :NC 3
          :DIMENSION 9)

    ;; This creates a sudoku problem, trying to mask 50 cells.  It is
    ;; not guaranteed that the specified number of cells are actually
    ;; masked.

    (sudoku:make-sudoku-mask
     (car (sudoku:make-multiple-sudoku-table 1 '(3 3) :random t))
     50)

    => #S(SUDOKU:STBL
          :TABLE #2A((0 0 1 6 0 0 0 0 0)
                     (5 0 0 0 0 0 7 0 9)
                     (0 8 0 4 0 0 3 0 5)
                     (4 0 7 8 0 2 0 0 1)
                     (2 0 5 9 0 3 0 0 0)
                     (9 1 0 0 4 6 0 3 0)
                     (7 0 0 2 0 0 0 0 0)
                     (0 0 0 0 7 0 9 2 6)
                     (0 9 0 0 0 4 0 0 0))
          :NR 3
          :NC 3
          :DIMENSION 9)
       #S(SUDOKU:STBL
          :TABLE #2A((3 7 1 6 9 5 2 8 4)
                     (5 2 4 1 3 8 7 6 9)
                     (6 8 9 4 2 7 3 1 5)
                     (4 3 7 8 5 2 6 9 1)
                     (2 6 5 9 1 3 4 7 8)
                     (9 1 8 7 4 6 5 3 2)
                     (7 5 6 2 8 9 1 4 3)
                     (8 4 3 5 7 1 9 2 6)
                     (1 9 2 3 6 4 8 5 7))
          :NR 3
          :NC 3
          :DIMENSION 9)
       #S(SUDOKU:STBL
          :TABLE #2A((1 1 0 0 1 1 1 1 1)
                     (0 1 1 1 1 1 0 1 0)
                     (1 0 1 0 1 1 0 1 0)
                     (0 1 0 0 1 0 1 1 0)
                     (0 1 0 0 1 0 1 1 1)
                     (0 0 1 1 0 0 1 0 1)
                     (0 1 1 0 1 1 1 1 1)
                     (1 1 1 1 0 1 0 0 0)
                     (1 0 1 1 1 0 1 1 1))
          :NR 3
          :NC 3
          :DIMENSION 9)

    ;; Solve a sudoku problem.

    (sudoku::solve-sudoku
              #S(SUDOKU:STBL
                 :TABLE #2A((0 0 1 6 0 0 0 0 0)
                            (5 0 0 0 0 0 7 0 9)
                            (0 8 0 4 0 0 3 0 5)
                            (4 0 7 8 0 2 0 0 1)
                            (2 0 5 9 0 3 0 0 0)
                            (9 1 0 0 4 6 0 3 0)
                            (7 0 0 2 0 0 0 0 0)
                            (0 0 0 0 7 0 9 2 6)
                            (0 9 0 0 0 4 0 0 0))
                 :NR 3
                 :NC 3
                 :DIMENSION 9))

    => #S(SUDOKU:STBL
          :TABLE #2A((3 7 1 6 9 5 2 8 4)
                     (5 2 4 1 3 8 7 6 9)
                     (6 8 9 4 2 7 3 1 5)
                     (4 3 7 8 5 2 6 9 1)
                     (2 6 5 9 1 3 4 7 8)
                     (9 1 8 7 4 6 5 3 2)
                     (7 5 6 2 8 9 1 4 3)
                     (8 4 3 5 7 1 9 2 6)
                     (1 9 2 3 6 4 8 5 7))
          :NR 3
          :NC 3
          :DIMENSION 9)

Notes:

  * This program uses images included in Gimp: Logos of "Basic I" &
    "Comic Book".

  * As you see, the images are very primitive, except that came from
    Gimp ("Number(Comic)" in Style and Check messages).  You can add
    your images for cells.

    - Create a directory under images.

      $ cd images
      $ mkdir <your-image-dir>

    - Put 100-pixel x 100-pixel xpm images under the directory, at
      least 4 of them, whose names are "s4-<image-name>.xpm".

      $ cp <somewhere>/s4-*.xpm <your-image-dir>/

    - Run resize-sudoku-images.lisp.  It creates images for sudoku
      with sizes of 6^2, 8^2 and 9^2.

      $ ./resize-sudoku-images.lisp <your-image-dir>

    - Add images to Style menu.  For example, if you created
      s*-cat.xpm, s*-dog.xpm, s*-monkey.xpm and s*-bird.xpm under
      images/animals directory:

      (sudoku-mcclim:add-image
       '("Image(animals)" "animals" ("cat" "dog" "monkey" "bird")))

      then, "Image(animals)" will appear in Style menu.

About

sudoku problem generator & solver for Common Lisp & McCLIM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published