Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Sudoku/Thorkil Naur
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Command line interface to sdkSolve == The Main module contained in SdkMSol2.hs provides a command line interface to the SuDoku solver. Here is an example of a call of the solver that uses runhugs: <pre> runhugs SdkMSol2 \ tn1 \ Traditional 3 \ -#123456789 \ 1-53---9- \ ---6----- \ ------271 \ 82------- \ ---487--- \ ------53- \ 23------- \ --7-59--- \ --6---8-4 </pre> This is a command for a Linux system. A similar command can be used under Windows. (I usually keep these long commmands in individual command files, i.e. Shell scripts or BAT files.) And, of course, SdkMSol2 can be compiled by GHC and run in a similar manner. The first parameter "tn1" is simply a name for the puzzle used in the output. In this case, the first (and so far only) SuDoku puzzle invented by Yours Truly. The next parameter "Traditional" selects the class of puzzle desired. Following parameters may be used to qualify specific puzzles within the class, in this case the "3" which selects the ordinary 9*9 SuDoku puzzle. The remaining parameters lay out the initial contents of the rectangular board. Parameters of the form <pre> <character>#<list of characters> </pre> ("#" is used rather than "=" which gives problems in BAT files) are definitions where the first character is defined to represent the set of characters listed. Thus, the parameter "-#123456789" defines "-" to represent the set "123456789". Parameters not of this form represent rows of the, generally rectangular, board: In such a row, characters that have been "defined" represent their set, other characters represent the set containing that single character. (The command line interface thus restricts the elements used by the solver to be individual characters. However, the solver itself is not restricted to handle single-character elements.) Notice that the puzzle class with parameters represents the constraint sets used independently of the board, whose shape is basically defined by the number of rows specified and their maximum length. Conflicts are not verified explicitly, but generally result in (sometimes obscure) runtime errors. Selected lines from the output of running the above command: <pre> SdkMSol2: 2006-Jun-04 13.37 SdkMSol2(tn1) Height 9 Width 9 1-53---9- ---6----- ------271 82------- ---487--- ------53- 23------- --7-59--- --6---8-4 tn1: Problem: 1 123456789 5 3 123456789 123456789 123456789 9 123456789 123456789 123456789 123456789 6 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 2 7 1 8 2 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 4 8 7 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 5 3 123456789 2 3 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 7 123456789 5 9 123456789 123456789 123456789 123456789 123456789 6 123456789 123456789 123456789 8 123456789 4 tn1: Closure by field: ... 1 78 5 3 27 28 4 9 6 79 479 2 6 1479 14 3 8 5 369 4689 3489 589 49 458 2 7 1 8 2 139 159 1369 1356 1679 4 79 3569 1569 139 4 8 7 169 16 2 679 14679 149 129 1269 126 5 3 8 2 3 18 18 46 46 79 5 79 4 18 7 128 5 9 16 126 3 59 59 6 7 123 123 8 12 4 tn1: Solutions: 1 7 5 3 2 8 4 9 6 9 4 2 6 7 1 3 8 5 3 6 8 5 9 4 2 7 1 8 2 9 1 3 5 6 4 7 6 5 3 4 8 7 9 1 2 7 1 4 9 6 2 5 3 8 2 3 1 8 4 6 7 5 9 4 8 7 2 5 9 1 6 3 5 9 6 7 1 3 8 2 4 tn1: Total of 1 solutions tn1: CPU Used: 53.4 </pre> Thus, the problem is stated (in two different ways), the sequence of intermediate boards resulting from performing field reduction on the initial board is printed and, finally, all the solutions are printed. (And since field reduction is also carried out, starting from the initial board, as part of finding the solution, field reduction of the initial board is actually carred out twice. Something that may be changed by editing the sdkProcessSuDoku function.) Here is an example of a command for solving a 16*16 SuDoku puzzle: <pre> runhugs SdkMSol2 \ MasterSUDOKU_106_20051208 \ Traditional 4 \ -#0123456789ABCDEF \ --6--37--B-C--E- \ -C4A08D-5-7-2--- \ -9--F----0--C1-- \ -1E8--6-2D-4--5- \ F-CBE---12-39-7- \ -A8-B-----F7---1 \ 7-D4-9---C-0---8 \ --------D-9--B-- \ --2--0-9-------- \ E---8-A---4-12-B \ 4---67-----F-90- \ -0-FD-C1---E38-5 \ -B--4-97-E--80A- \ --F0--2----9--3- \ ---E-F-3-A0B6C1- \ -4--C-0--81--F-- </pre> The final example uses the clover class: <pre> runhugs SdkMSol2 \ JuleSuDoku_Fem_I_En_20060102 \ Clover 3 \ -#123456789 \ ---6327-1...--7---23- \ --24--5-6...4--1----- \ --85---9-...1-5-8--7- \ 94----127...-6----8-5 \ 1-5------...-3---714- \ 87--9----...-41-62-97 \ 5873-------3----3--19 \ --4--8----4----52--6- \ 2---65-----9---7--58- \ ......5-----12-...... \ ......-8---67-9...... \ ......--1372---...... \ 64---9----14----4---- \ --263-------------74- \ -93-4----93----5-3--2 \ ----68-7-...2-5--8-9- \ ---------...84--9-57- \ 5--3--84-...-----5-26 \ --54-36--...7-------- \ 2--9-5--7...-5438-61- \ -3782----...--37694-- </pre> Notice the dots (".") used. They do not enter any constraint sets, but are needed to fill out the board.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width