CS 5541
Program 2 - Constraint Satisfaction Problems (Sudoku)
Due November 11, 2010
50 points

Introduction

Sudoku is a classic game involving constraint satisfaction. If you do not know how to play Sudoku you can learn the rules at this link. In a Sudoku problem parts of a 9x9 grid are set to values from 1 to 9 and the player must fill in the rest of the grid based on certain constraints:

2    
6    
5 8  
     
    4
6 9 2
    8
  1  
  7  
     
     
8   5
8 2  
1   9
  7 6
7   4
     
     
  5  
  2  
4    
2 6 3
7    
     
  4 9
    1
    7

For example, the 2 at position 0,0 means that no 2 can occur in the first row or first column, and no other spot may be a 2 in the upper 3x3 grid.

Some Implementation Details

You can find the code I have implemented at prog2.lisp. This code has a routine solve_sudoku that takes in an initial description of a problem. For example, the sudoku grid above would be described by the variable sudoku_m1:

(setq sudoku_m1
    '((0 0 2) (0 8 8)
      (1 0 6) (1 5 4) (1 7 1)
      (2 0 5) (2 1 8) (2 3 6) (2 4 9) (2 5 2) (2 7 7)
      (3 3 8) (3 4 2) (3 6 7) (3 8 4)
      (4 3 1) (4 5 9)
      (5 0 8) (5 2 5) (5 4 7) (5 5 6)
      (6 1 5) (6 3 2) (6 4 6) (6 5 3) (6 7 4) (6 8 9)
      (7 1 2) (7 3 7) (7 8 1)
      (8 0 4) (8 8 7)))

Other routines in prog2.lisp are:

To complete the code you must complete the two routines:

Testing

The file sudoku.lisp contains 9 problems defined by a variable each. Once you have completed your code run the routine solve_sudoku on each of those variables and report how many nodes are searched during the backtrack search and then what the final solution is.

What To Hand In

Hand in clean, nicely commented copies of all of your code (make sure to include the class code so we can tell if anything is changed). In addition, print out the solution produced for each problem and how many nodes are investigated during your backtrack search. Finally, email your code to me at rmaclin@d.umn.edu.