» ASP Competition

Sudoku Puzzle

Problem description

Given an NxN grid board (N=9 or 25), where N is a square number N=M2, fill it with integers from 1 to N so that each row, each column, and each of the N MxM boxes contains each of the integers from 1 to N exactly once. Suppose the rows are numbered 1 to N from left to right, and the columns are numbered 1 to N from top to bottom. The boxes are formed by dividing the rows from top to bottom every M rows a time and dividing the columns from left to right every M columns a time. 

Input format

The input file contains the following:

a. The atom size(N) that states the size of the board. N is a square number.

b. The predicate square/3 that gives pre-filled squares:

    square(R1,C1,I1). square(R2,C2,I2). ...

where each atom square(Ri,Ci,Ii) states that the square at row Ri and column Ci is filled with integer Ii. 

Output format

The output gives a solution as a predicate sol/3: 

sol(1,1,I11). sol(1,2,I12). ... sol(1,N,IiN).
...
sol(N,1,IN1). sol(N,2,IN2).... sol(N,N,INN).

where the atom sol(R,C,I) means that the integer placed at (R,C) is I.

Sample input

size(9). 
square(2,1,1). square(6,1,7). square(7,1,8). square(8,1,5). square(9,1,9). square(2,2,6). square(3,2,5). square(6,2,1). square(2,3,9). square(5,3,8). square(8,3,1). square(9,3,3). square(1,4,4). square(3,4,8). square(5,4,3). square(7,4,5). square(9,4,6). square(3,5,1). square(7,5,2). square(1,6,9). square(3,6,2). square(5,6,4). square(7,6,1). square(9,6,7). square(1,7,7). square(2,7,2). square(5,7,1). square(8,7,6). square(4,8,2). square(7,8,9). square(8,8,8). square(1,9,1). square(2,9,8). square(3,9,9). square(4,9,4). square(8,9,7). 

Sample output

sol(1,1,3). sol(1,2,8). sol(1,3,2). sol(1,4,4). sol(1,5,6). sol(1,6,9). sol(1,7,7). sol(1,8,5). sol(1,9,1). sol(2,1,1). sol(2,2,6). sol(2,3,9). sol(2,4,7). sol(2,5,3). sol(2,6,5). sol(2,7,2). sol(2,8,4). sol(2,9,8). sol(3,1,4). sol(3,2,5). sol(3,3,7). sol(3,4,8). sol(3,5,1). sol(3,6,2). sol(3,7,3). sol(3,8,6). sol(3,9,9). sol(4,1,6). sol(4,2,3). sol(4,3,5). sol(4,4,1). sol(4,5,7). sol(4,6,8). sol(4,7,9). sol(4,8,2). sol(4,9,4). sol(5,1,2). sol(5,2,9). sol(5,3,8). sol(5,4,3). sol(5,5,5). sol(5,6,4). sol(5,7,1). sol(5,8,7). sol(5,9,6). sol(6,1,7). sol(6,2,1). sol(6,3,4). sol(6,4,2). sol(6,5,9). sol(6,6,6). sol(6,7,8). sol(6,8,3). sol(6,9,5). sol(7,1,8). sol(7,2,7). sol(7,3,6). sol(7,4,5). sol(7,5,2). sol(7,6,1). sol(7,7,4). sol(7,8,9). sol(7,9,3). sol(8,1,5). sol(8,2,2). sol(8,3,1). sol(8,4,9). sol(8,5,4). sol(8,6,3). sol(8,7,6). sol(8,8,8). sol(8,9,7). sol(9,1,9). sol(9,2,4). sol(9,3,3). sol(9,4,6). sol(9,5,8). sol(9,6,7). sol(9,7,5). sol(9,8,1). sol(9,9,2). 

Authors: Neng-Fa Zhou
Affiliation: CUNY Brooklyn College