Problem in general : we have map 8*8 and we have to fill the empty squares with number from 1 to 6.But in each column and raw number should be met only 1 time.Two squares in each row and column are left empty.Numbers from both sides,up and down show us the first number,that should appear(but it can appear after two empty squares).
So,now i have this code,which finally works on swi-prolog for 4*4 map.
:- module(ab, [ab/0]).
:- [library(clpfd)].
gen_row(Ls):-length(Ls, 4), Ls ins 0..3.
transpose(Ms, Ts) :-
%must_be(list(list), Ms),
( Ms = [] -> Ts = []
; Ms = [F|_],
transpose(F, Ms, Ts)
).
transpose([], _, []).
transpose([_|Rs], Ms, [Ts|Tss]) :-
lists_firsts_rests(Ms, Ts, Ms1),
transpose(Rs, Ms1, Tss).
lists_firsts_rests([], [], []).
lists_firsts_rests([[F|Os]|Rest], [F|Fs], [Os|Oss]) :-
lists_firsts_rests(Rest, Fs, Oss).
ab :-
Rows = [R1,R2,R3,R4],
maplist(gen_row, Rows),
transpose(Rows, [C1,C2,C3,C4]),
maplist(all_distinct, [R1,R2,R3,R4]),
maplist(all_distinct, [C1,C2,C3,C4]),
start(R2, 3),
start(R3, 3),
finish(R3, 2),
start(C3, 1),
finish(C2, 2),
maplist(writeln, [R1,R2,R3,R4]).
finish(X, V) :-
reverse(X, Y),
start(Y, V).
start([0,Y|_], Y).
start([Y|_], Y).
But,it doesn't support the problem with 2 empty places for bigger area,like 8*8 puzzle.Any hint's?