Commit 7383903e authored by Amin Raslan's avatar Amin Raslan
Browse files

Update officer_problem.pl

parent cf9ec630
......@@ -7,15 +7,15 @@ officer_problem(N, Square) :-
maplist(set_inner_length(2), Square),
append(Square, Vs),
maplist(set_domain(N), Vs),
square2lists(Square, L1, L2),
maplist(all_different,L1),
maplist(all_different,L2),
square2lists(Square, Xs, Ys),
maplist(all_different,Xs),
maplist(all_different,Ys),
transpose(Square, TransposedSquare),
square2lists(TransposedSquare, L3, L4),
maplist(all_different,L3),
maplist(all_different,L4),
square2lists(TransposedSquare, TXs, TYs),
maplist(all_different, TXs),
maplist(all_different, TYs),
maplist(labeling([]), Vs),
unique_combination(Square),
unique_combination_xy(Square),
maplist(portray_clause, Square).
set_inner_length(_,[]) :- !.
......@@ -34,21 +34,21 @@ square2lists([[H|TH]|TR], [[H1|T1]|TR1], [[H2|T2]|TR2]) :-
H = [H1,H2],
square2lists([TH|TR], [T1|TR1], [T2|TR2]).
unique_combination([_]) :- !.
unique_combination([H|T]) :-
unique_combination(H,T),
unique_combination(T).
unique_combination_xy([_]) :- !.
unique_combination_xy([H|T]) :-
unique_combination_xy(H,T),
unique_combination_xy(T).
unique_combination([],_) :- !.
unique_combination([H|T],Lists) :-
unique_combination_xy([],_) :- !.
unique_combination_xy([H|T],Lists) :-
H = [H1,H2],
unique_combination(H1, H2, Lists),
unique_combination(T, Lists).
unique_combination_xy(H1, H2, Lists),
unique_combination_xy(T, Lists).
unique_combination(_,_,[]) :- !.
unique_combination(E1, E2, [[H|TH]|TR]) :-
unique_combination_xy(_,_,[]) :- !.
unique_combination_xy(E1, E2, [[H|TH]|TR]) :-
H = [H1,H2],
(H1 == E1 -> (H2 #\= E2, unique_combination(E1, E2, TR));
unique_combination(E1, E2, [TH|TR])).
(H1 == E1 -> (H2 #\= E2, unique_combination_xy(E1, E2, TR));
unique_combination_xy(E1, E2, [TH|TR])).
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment