sudoku-clj/README

68 lines
3 KiB
Text
Raw Permalink Normal View History

2010-07-24 12:39:47 +01:00
# ray1729.clojure.sudoku
2010-07-24 14:17:10 +01:00
A naive Sudoku puzzle solver written in Clojure.
This solver implements a trivial strategy consisting of elimination
and trial-and-error.
2010-07-24 12:39:47 +01:00
## Usage
2010-07-24 14:17:10 +01:00
(require '[ray1729.clojure.sudoku.core :as sudoku])
(def g (sudoku/parse-grid "400000805030000000000700000020000060000080400000010000000603070500200000104000000"))
(sudoku/solved? g)
;;=> false
(sudoku/print-grid g)
;; ...4..... 1....67.9 12...67.9 | 1.3.....9 .23..6..9 12...6..9 | .......8. 123.....9 ....5....
;; .2...6789 ..3...... 12..56789 | 1..45..89 .2.456..9 12.456.89 | 12...67.9 12.4....9 12.4.67.9
;; .2...6.89 1...56.89 12..56.89 | ......7.. .23456..9 12.456.89 | 123..6..9 1234....9 1234.6..9
;; ------------------------------+-------------------------------+------------------------------
;; ..3...789 .2....... 1.3.5.789 | ..345...9 ..345.7.9 ...45.7.9 | 1.3.5.7.9 .....6... 1.3...789
;; ..3..67.9 1...567.9 1.3.567.9 | ..3.5...9 .......8. .2..567.9 | ...4..... 123.5...9 123...7.9
;; ..3..6789 ...456789 ..3.56789 | ..345...9 1........ .2.4567.9 | .23.5.7.9 .23.5..89 .23...789
;; ------------------------------+-------------------------------+------------------------------
;; .2.....89 .......89 .2.....89 | .....6... ...45...9 ..3...... | 12..5...9 ......7.. 12.4...89
;; ....5.... .....6789 ..3..6789 | .2....... ...4..7.9 1..4..789 | 1.3..6..9 1.34...89 1.34.6.89
;; 1........ .....6789 ...4..... | ....5..89 ....5.7.9 ....5.789 | .23.56..9 .23.5..89 .23..6.89
(def s (sudoku/solve g))
(sudoku/solved? s)
;;=> true
(sudoku/print-grid s)
;; ...4..... 1........ ......7.. | ..3...... .....6... ........9 | .......8. .2....... ....5....
;; .....6... ..3...... .2....... | 1........ ....5.... .......8. | ........9 ...4..... ......7..
;; ........9 ....5.... .......8. | ......7.. .2....... ...4..... | ..3...... 1........ .....6...
;; ------------------------------+-------------------------------+------------------------------
;; .......8. .2....... ....5.... | ...4..... ..3...... ......7.. | 1........ .....6... ........9
;; ......7.. ........9 1........ | ....5.... .......8. .....6... | ...4..... ..3...... .2.......
;; ..3...... ...4..... .....6... | ........9 1........ .2....... | ......7.. ....5.... .......8.
;; ------------------------------+-------------------------------+------------------------------
;; .2....... .......8. ........9 | .....6... ...4..... ..3...... | ....5.... ......7.. 1........
;; ....5.... ......7.. ..3...... | .2....... ........9 1........ | .....6... .......8. ...4.....
;; 1........ .....6... ...4..... | .......8. ......7.. ....5.... | .2....... ........9 ..3......
2010-07-24 12:39:47 +01:00
## Installation
FIXME: write
2010-07-24 14:17:10 +01:00
## See Also
This code inspired by: http://norvig.com/sudoku.html
All you want to know about Sudoku: http://www.sudokuwiki.org/
2010-07-24 12:39:47 +01:00
## License
2010-07-24 14:17:10 +01:00
Copyright (C) 2010, Ray Miller <ray@1729.org.uk>.
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
PUBLIC LICENSE, <http://www.eclipse.org/org/documents/epl-v10.php>.
ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
RECIPIENTS ACCEPTANCE OF THIS AGREEMENT.