CSCI 4500/6500 Programming Languages

Project 6: Hex Sudoko

Fun :- Prolog

Under construction

Assigned: Thursday April 13, 2006
Due: Thursday April 27, 2006

Friday May 05, 2006


Collaboration Policy - Read Carefully

You must work on this project individually, but you may discuss this assignment with other students in the class and ask and provide help in useful ways, preferable over our email list so we can all benefit from your great ideas. You may consult any outside resources you wish including books, papers, web sites and people (but no penguins or sea urchins).

If you use resources other than the class materials, indicate what you used along with your answer.

Objective:

The main objective for this assignment is to familiarize yourself with a logical language, in particular Prolog. You may use swi-prolog that is already installed on atlas (at /usr/local/bin) or you may install your own. I suggest that you install your own. I suggest that you also use the Window IDE, which is an interactive development environment, to develop your prolog program. The instructor, who has a MAC, has not used the Window IDE, so you are on you own, but note it is recommended.

 

Runs on Microsoft Windows, MacOS X (yay!), UNIX.

Tutorials:

Some tutorials on Prolog:

JR Fisher’s original tutorial :

Roman Barták’s interactive tutorial:

Mike Rosner’s crash course:

James Lu and Jerud Mead’s tutorial:

James Power’s tutorial:

Background:

Sudoku ("Suuji wa dokushin ni kagiru" meaning "the digits must remain single"" in Japanese) is a logic placement puzzle. Typically the puzzle is a 9x9 grid of 81 cells that is further subdivided into 9 3x3 boxes (or sub-grids). The goal is to place digits numbered from 1 to 9 in each cell so that each digit only appear once in a row, once in a column and once in each of the 3x3 boxes or sub-grids.

The puzzle originated as "Number Place" published in the Math Puzzler and Logic Puzzler in New York in the late 1970s by Dell Magazines. It that later evolved into Su doku in Japan. Sudoko assumes that there are no more than thirty clues and that the initial clues must be given in a pleasing, symmetrical pattern, just like bonsai, Japanese miniature trees that are trained into pleasing shapes.

There are many variations of Sudoko, the differences range from varying the size of the grid ranging from 4x4 grids with 2x2 regions, 5x5 grids with pentomino regions or adding new restrictions, such as "uniqueness" of numbers on diagonals, colored "uniqueness regions' or even three dimensional Sudoko's.

Larger grids are also possible, with Daily SuDoku's 12×12-grid Monster SuDoku, the Times likewise offers a 12×12-grid Dodeka sudoku with 12 regions each being 4×3, Dell regularly publishing 16×16 Number Place Challenger puzzles (the 16×16 variant often uses 1 through G rather than the 0 through F used in hexadecimal), and Nikoli proffering 25×25 Sudoku the Giant behemoths.

http://en.wikipedia.org/wiki/Sudoku give more details on solution methods and strategies. For an interactive web like puzzle try http://www.websudoku.com/ which lets you solve Sudoko interactively under a time constraints.

Description:

Your assignment is to create a program, written in Prolog that solves Sudoko puzzles that are either 4x4 grids with 2x2 regions, 6x6 grids with 2x3 sub-grids, 9x9 grids with 3x3 regions, 12x12 grids with 3x4 regions and 16x16 grids with 4x4 regions. The alphabet for each grid size is listed below, but in general is reflected by the grid size (but not quite). For example, the number base for a 16x16 grid would be base-16, hexadecimal, using the symbols 0-9 and A-F (upper case only).

You program will take as input a partially filled in puzzle appropriate for the grid size that you are solving. Empty cells will be represented by hyphens ('-'). Here is a sample input of a 16x16 puzzle.

   

1--234--B-6---7-
--8---7--3--906A
-B--0--1-C-A--D-
3--E2--D---9--B-
C---8--0-B2-1E--
-A76---F---E--5C
---0-5E--4-8--A-
F--59B--1-----8-
-2-----C--B58--3
-C--E-3--D8-F---
58--1---2---C9E-
--B4-6F-C--7---5
-3--B---6--4A--F
-7--F-5-D--1--2-
A1E9--C--2---D--
-D---A-2--C35--B

   

The output should look like the input except the hyphens should be replaced by digits.

HINTS: Each Sudoko puzzle have one unique solution, so you will not need to worry about generating more than one answer (since there are none).

 

 

Puzzle sizes:

Here is a listing of the puzzle sizes with their box size and alphabet. You may support more than these if you like, but it is not required. There are also pictures of each puzzle size listed further below. Most of them are available at http://www.dailysudoku.com.

 

Puzzle Type Size Box Size Alphabet
Kids 4x4 2x2 1 to 4
Kids 6x6 2x3 1 to 6
Kids/Classic 9x9 3x3 1 to 9
Monster 12x12 3x4 1 to 9, A, B, C
Monster 16x16 4x4 1 to 9, 0, A to F

 

 

 

 

 

 

Input/Output:

A challenge of this assignment is to read and translate the initial configuration given by the input file into constraints (or facts) that should be incorporated into your prolog program (knowledge database). One solution is to use a helper program written in a different language that parses the input and then generates prolog constraints on the fly to be added to your knowledge base. Another solution is to use prolog file utilities that were shown in class by Keith. Another challenge is to translate the output of prolog to the output format described above (except that hyphens are replaced my digits). The solution to this is similar to the input problem solution, i.e. use a helper program that scans the output of prolog and then outputs the solution matrix OR use prolog file utilities.

If you use the helper programs, then the pipeline should look as follows:

 

We will provide helper programs for scanning input and producing output or you may write your own (maybe in Python) or you may use the file utilities in prolog.

 

Requirements:

You may not use Prolog's AllDiff primitive. You may however code your own version of Alldiff.

Submitting:

Submitting

  1. Create a directory x500_program6
  2. Put all the materials needed (all files) in the above directory (including your README.txt file)
  3. Submit via the 'submit' command (while on atlas.cs.uga.edu)
{atlas:maria} submit x500_program6

 

 

 

Thanks to Min-Yen Kan <kanmy@comp.nus.edu.sg> http://www.comp.nus.edu.sg/~kanmy/courses/3243_2006/hw-hexSudoku.html
Description from Wikipedia and Gil Galanti's article at http://www.conceptispuzzles.com/articles/sudoku/