welcome: please sign in
location: FinalProblemDescriptions / MagicSquareSets

Magic Square Sets

Problem Description

Given the size n of the grid, the type of magic square problem to be considered and some clue on the contents of some cells, the contents of all other cells must be determined so that the constraint imposed by the considered problem are satisfied. Normal magic squares: a magic square of order 'n' is an arrangement of n2 numbers, 1..n2, in a square, such that the 'n' numbers in all rows, all columns, and both diagonals sum to the same constant n*(n^2+1)/2. It is known that the magic square of any order exists.

Semimagic squares: it is a relaxed normal magic square in the sense that only the rows and columns but not necessarily the diagonals sum to the magic constant n*(n^2+1)/2.

Panmagic squares: it is a magic square with the additional property that the broken diagonals, i.e. the diagonals that wrap round at the edges of the square, also add up to the magic constant n*(n^2+1)/2. The Number of distinct (modulo rotation and reflection) panmagic square of order n=1,2,3,4,5,6 are 1, 0, 0, 48, 3600, 0 respectively.

Associative magic squares: it is a magic square for which every pair of numbers symmetrically opposite to the center sum up to the same value n^2+1. The number of distinct (modulo rotation and reflection) associative magic squares of order n=1,2,3,4,5,6 are 1,0,1,48,48544,0 respectively.

Predicates

Input format

size/1, size(N) means the order of the magic square is 'N'.

type/1, is used to discriminate the type of magic square to be considered. If only type(semi) is given, it means that the square is required to be a semi magic square. If type(semi) and type(normal) are given, the normal magic squares problem has to be considered. If type(pan) (resp. type(assoc)) is also given then the panmagic (resp. associative magic) square problem has to be considered.

sqr/3, sqr(I,J,V) means the entry (I,J) is assigned the value V. Some entries are fixed by a set of facts for sqr(I,J,V).

Output format

sqr/3, sqr(I,J,Value) means the number Value is assigned at the entry (I,J) of the square.

Example(s)

Input:

size(4). type(semi).
sqr(1,3,12). sqr(2,1,14). sqr(3,2,10). sqr(4,4,16). sqr(4,1,4). sqr(1,1,13). sqr(2,4,1). 
sqr(1,1,13). sqr(1,3,12). sqr(2,1,14). sqr(2,4,1). sqr(3,2,10). sqr(4,1,4). sqr(4,4,16). 
sqr(1,4,2). sqr(3,1,3). sqr(4,3,5). sqr(3,3,6). sqr(1,2,7).

Ouput: sqr(2,2,8). sqr(4,2,9). sqr(2,3,11). sqr(3,4,15).

Author(s)

ASP Competition 2011: FinalProblemDescriptions/MagicSquareSets (last edited 2011-02-02 19:19:39 by MarioAlviano)