

carre_latin(L,N) :-
     length(L, N),
     constraint_lg(L,N),
     constraint_col(L,1,N),
     flatten(L,Ls),
     fd_labelingff(Ls),
    ecriture(L).  

constraint_lg([],_).
constraint_lg([L|Ls],N):-
    length(L, N),
    fd_domain(L, 1, N),   
    fd_all_different(L),
    constraint_lg(Ls,N).
  
constraint_col(L,N,N):-
	nth(N,L,C),
        fd_all_different(C).

constraint_col(L,I,N):-
        I < N,
	nth(I,L,C),
        fd_all_different(C),
        I1 is I+1,
	constraint_col(L,I1,N).	

  
ecriture([L1|L]):-
	 write(L1),nl,  ecriture(L).
ecriture([]).



 /*
| ?- carre_latin(L,8), cpu_time(T).
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7,8]

L = [[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8],[1,2,3,4,5,6,7,8]]
T = 32 ? 

(1 ms) yes
*/



