% Find all 3 by 3 magic squares.
% d(D) is for digit
d(1). d(2). d(3). d(4). d(5). d(6). d(7). d(8). d(9).
% a row has 3 different digits that add up to 15
row(X,Y,Z):-d(X),d(Y), X=\=Y, d(Z),X=\=Z, Y=\=Z, X+Y+Z=:=15.

col(X,Y,Z):-X=\=Y, Y=\=Z, X=\=Z, X+Y+Z=:=15.

diag(X,Y,Z):-X=\=Y, Y=\=Z, X=\=Z, X+Y+Z=:=15.

printrow(A,B,C):-write(A),write(B),write(C),nl.

out(A,B,C,D,E,F,G,H,I):-nl,
	printrow(A,B,C),
	printrow(D,E,F),
	printrow(G,H,I).

go:-	row(A,B,C),
	row(D,E,F),
	row(G,H,I), 
	col(A,D,G),col(B,E,H),col(C,F,I),
	diag(A,E,I), diag(G,E,C),
	out(A,B,C,D,E,F,G,H,I).

