Fall 2012, David Matuszek
In Sudoku, you are given a 9x9 grid, divided into nine 3x3 "boxes," as shown on the right. Each box has nine "cells," and some of these cells have digits in them (but most are blank).
The puzzle is to fill in the rest of the grid so that every row, every column, and every 3x3 box contains the digits 1 through 9. Your assignment is to write a program to partially solve Sudoku puzzles.
This image is from http://www.sudoku.com/, which is a very nice site with additional explanations and puzzles (and a Sudoku program for sale).
Your job is to write a program to solve, or partially solve, Sudoku puzzles.
Ask the user to locate a text file (by using a
JFileChooser) containing a Sudoku puzzle. The file should contain a Sudoku puzzle to be solved. The format should be nine lines, with nine numbers on a line, separated by whitespace (spaces and/or tabs). For extra neatness, allow blank lines in the input. Use underscore,
_, to indicated a "blank" (unfilled) location in the puzzle. For example:
_ _ 4 _ _ _ _ 6 7 3 _ _ 4 7 _ _ _ 5 1 5 _ 8 2 _ _ _ 3
Create a 9x9 array of lists. Each list will initially contain the digits 1 through 9.
Read in a puzzle from a file. For each filled-in value in the puzzle, set the corresponding list in your array to contain just that one number. (This means that a "known" location in the array is one containing a list with a single element.
Print the array you just read in.
Repeat the following, as many times as necessary, until you can make no further changes:
Print the solved puzzle in the same format, or in a "prettier" format if you like (with vertical bars and horizontal lines).
For each remaining unsolved location in the array, print out the row and column of the location (as 1 through 9, not 0 through 8!), and the remaining digits that could possibly still be in that location.
Every method should have Scaladoc comments. Be sure to use the
@author tag in the comment for the main object.
def, up to a maximum of 5 points.
=>, up to a maximum of 10 points.
Some, up to a maximum of 30 points
while, 5 points for each occurrence of
Array(except for the one required occurrence in
def main), and 10 points for each occurrence of
null. (This is to get you to use
List, and maybe
The reasons for these rules are twofold: (1) They are intended to get you using some of the unique Scala constructs, and (2) It is easy to write a program to count these keywords.
Wednesday, November 14 16, before 6am, via Blackboard.