Scala Assignment 1: Easy Sudoku
Fall 2010, David Matuszek

Purpose of this assignment

General idea of the assignment

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 solve easy Sudoku puzzles.

A problem is "easy" if, at all times, there is at least one location in the grid that has all but one of the nine digits occurring in the same row, column, or box.

For example, in the example puzzle, look at the bottom right-hand corner of the middle box in the top row of boxes (that is, row 2, column 5--remember to start counting with zero). The digits 2 and 1 occur in the same row; the digits 1, 3, 4, and 5 occur in the same box; and the digits 4, 5, 7, 1, 6, and 8 occur in the same column. The only missing digit is 9, which must perforce go into this location.


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).

 
Roll your mouse on and off the grid.
You may have to wait for the page to load fully

Details

Your job is to write a program to solve "easy" Sudoku puzzles.

Ask the user to locate a text file (possibly 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 zero to indicated a "blank" (unfilled) location in the puzzle. For example:

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

Print the solved puzzle in the same format, or in a "prettier" format if you like (with vertical bars and horizontal lines).

Due date

Tuesday, November 23, before midnight, via Blackboard.