CSE 150 Programming Assignment #2: Solving Sudoku Puzzles, Assignments of Computer Science

A programming assignment for a computer science course where students are required to write a program to solve sudoku puzzles of various sizes. The assignment covers different file formats, logic for reading and processing puzzles, and various heuristics for selecting the next variable and value to try. Students are encouraged to test their programs on different puzzles and evaluate the performance of different heuristics.

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-vz6
koofers-user-vz6 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 150 Programming Assignment #2
Date assigned: April 24, 2007
Date due: 11:59:59 May 3, 2007
In this programming assignment, you will be asked to solve Sudoku puzzles of various sizes.
Traditionally Sudoku puzzles are 9×9 grids filled with numbers between 1 and 9 such that:
Each digit appears once in each row.
Each digit appears once in each column.
Each digit appears once in each of 9 non-overlapping 3×3 boxes
Here we expand the problem somewhat to work on more general cases, such as the (simpler) 4×4
case (with 2×2 boxes) and the more complicated 16×16 case (with 4×4 boxes). (There are
versions that allow non-square boxes, but we won’t be generalizing to those). As is often the case
in AI, it’s often best to test with the small trivial cases and scale up to the harder ones (inefficient
implementations may make 16×16 impossible).
Simple sudoku (.ss) files are text files that describe a Sudoku puzzle. The format is pretty simple,
but there seems to be some flexibility. Blanks are marked with ‘.’, filled in numbers with their
corresponding digit. Interior lines for boxes are always marked with symbols, sometimes spaces
between characters are added, and sometimes additional info is provided. Test cases will be in
the first form given below, but many other formats are used on the web. Probably the simplest
and most robust method is to simply ignore all lines starting with a letter and all characters that
are not digits, ‘.’, or new lines. Typically .ss files are only for 9x9 puzzles, but your program
should be capable of reading any n x n puzzles where n is 4, 9, or 16. For 16x16, hexadecimal
will be used. Here’s a sample of the form we’ll be testing with:
...|...|...
2..|8.4|9.1
...|1.6|32.
-----------
...|..5|.4.
pf3
pf4

Partial preview of the text

Download CSE 150 Programming Assignment #2: Solving Sudoku Puzzles and more Assignments Computer Science in PDF only on Docsity!

CSE 150 Programming Assignment

Date assigned: April 24, 2007 Date due: 11:59:59 May 3, 2007 In this programming assignment, you will be asked to solve Sudoku puzzles of various sizes. Traditionally Sudoku puzzles are 9×9 grids filled with numbers between 1 and 9 such that:

  • Each digit appears once in each row.
  • Each digit appears once in each column.
  • Each digit appears once in each of 9 non-overlapping 3×3 boxes Here we expand the problem somewhat to work on more general cases, such as the (simpler) 4× 4 case (with 2×2 boxes) and the more complicated 16×16 case (with 4×4 boxes). (There are versions that allow non-square boxes, but we won’t be generalizing to those). As is often the case in AI, it’s often best to test with the small trivial cases and scale up to the harder ones (inefficient implementations may make 16×16 impossible). Simple sudoku (.ss) files are text files that describe a Sudoku puzzle. The format is pretty simple, but there seems to be some flexibility. Blanks are marked with ‘.’, filled in numbers with their corresponding digit. Interior lines for boxes are always marked with symbols, sometimes spaces between characters are added, and sometimes additional info is provided. Test cases will be in the first form given below, but many other formats are used on the web. Probably the simplest and most robust method is to simply ignore all lines starting with a letter and all characters that are not digits, ‘.’, or new lines. Typically .ss files are only for 9x9 puzzles, but your program should be capable of reading any n x n puzzles where n is 4, 9, or 16. For 16x16, hexadecimal will be used. Here’s a sample of the form we’ll be testing with: ...|...|... 2..|8.4|9. ...|1.6|32.

...|..5|.4.

While here’s another sample from the web using a different format: Puzzle: X-wing +-------+-------+-------+ | 3 4 5 | 1 9 2 | 7 6 8 | | 9 2 8 | 4 7 6 |. 3 1 | | 6 7 1 | 5 3 8 | 2 4 9 | +-------+-------+-------+ | 2 1 3 | 9 6 4 | 8. 7 | | 5 8 9 | 3 2 7 | 6 1 4 | | 7 6 4 | 8 1. | 9 2 3 | +-------+-------+-------+ | 4 9 2 | 7 5 1 | 3 8 6 | | 1 3 6 | 2 8 9 | 4 7 5 | | 8 5 7 | 6 4 3 | 1 9 2 | +-------+-------+-------+ Logistics: You can work alone or in groups of at most 3. Code must be submitted (with comments) by the due date. Use of Java for this assignment is strongly encouraged – if you'd rather use something else, please discuss it with the TA (if you would like to practice Matlab (you won’t need it this quarter), this is an assignment where it should work fine). A copy of your write up as a pdf should be included. Turn in the code using the turnin script. Hard copies of write-ups are due at the beginning of class the following class, printed and stapled. Code should be included in the printout. Write-ups should include a brief description of the approach taken, answers to any questions posed, and sample output on some examples. See below for more details on the content of the write up. Half of the points are based on the quality of the write-up and the comments. The other half are based on the performance of your code, both as reported in your write up and on a test set of problems. Bonus points may be awarded at the TA's discretion for going above and beyond the HW's description. Points will be deducted for not following these instructions. Note that no late programming assignments will be accepted! Project specifics

Google for pointers) that capture some of these higher order dependencies and can trim your search immensely. There will likely be some trade off, as better pruning will improve # of nodes visited but time-intensive pruning will eventually start increasing runtimes. Write up: Please describe the approach taken and how your program should be executed. What kind of testing did you do, and how did your methods fare? Often, Sudoku puzzles are rated by difficulty, so this is a variable you may want to measure over. Also, perform some analysis on the efficacy of the different approaches with different puzzles. Your write up should include at least one graph. Testing: Your programs will be run on several puzzles for each of the flags described above. Test set files will be in the first of the .ss formats described above (but we encourage you to accept the more general formats). Your own reported testing should be thorough enough that there are no surprises here. We’ll be including pointers to some .ss repositories on the discussion board. Lots of websites have downloadable .ss files, and some will even spawn novel puzzles for you on the fly. Programs will also be run using the –best flag and the scores here will be compared by a) # of nodes visited b) the total execution time. The best program(s) on each metric will receive 10 pts, the worst 1, and the remainder spread uniformly between. Hints: -Start testing on small, trivial problems. -You may want to introduce additional command line arguments for your testing. Be sure to document this.