Matrix 创建一个矩阵并排列每一行

Matrix 创建一个矩阵并排列每一行,matrix,prolog,permutation,latin-square,Matrix,Prolog,Permutation,Latin Square,我可以创建一个从0到N的列表并对其进行排列。但是我怎样才能把它变成矩阵,并且仅仅从矩阵(2,L)排列每一行呢 我不确定你的要求。以下是一个基于内置的可能答案 3 ?- [user]. |: matrix(N, Mat) :- length(Rows, N), maplist(numlist(1,N), Rows), maplist(permutation, Rows, Mat). % user://1 compiled 0.01 sec, 2 clauses true. 4 ?- matri

我可以创建一个从0到N的列表并对其进行排列。但是我怎样才能把它变成矩阵,并且仅仅从
矩阵(2,L)
排列每一行呢


我不确定你的要求。以下是一个基于内置的可能答案

3 ?- [user].
|: matrix(N, Mat) :- length(Rows, N), maplist(numlist(1,N), Rows), maplist(permutation, Rows, Mat).

% user://1 compiled 0.01 sec, 2 clauses
true.

4 ?- matrix(3, M).
M = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] ;
M = [[1, 2, 3], [1, 2, 3], [1, 3, 2]] ;
M = [[1, 2, 3], [1, 2, 3], [2, 1, 3]] ;
M = [[1, 2, 3], [1, 2, 3], [2, 3, 1]] ;
...

你是说你想创建一个N x N!矩阵,其中每一行都是相同长度列表的不同排列
N
?是的,我想创建nxn矩阵并排列每一行,直到它变成拉丁方
3 ?- [user].
|: matrix(N, Mat) :- length(Rows, N), maplist(numlist(1,N), Rows), maplist(permutation, Rows, Mat).

% user://1 compiled 0.01 sec, 2 clauses
true.

4 ?- matrix(3, M).
M = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] ;
M = [[1, 2, 3], [1, 2, 3], [1, 3, 2]] ;
M = [[1, 2, 3], [1, 2, 3], [2, 1, 3]] ;
M = [[1, 2, 3], [1, 2, 3], [2, 3, 1]] ;
...