更新时间:2023-11-25 23:09:22
总是可以定义更笼统的谓词并以狭窄的方式使用它:
Always good to define more general predicate and use it in a narrowed fashion:
perm(X,L):- mselect(X,L,[]).
mselect([A|B],L,R):- select(A,L,M), mselect(B,M,R).
mselect([],L,L).
member
不好,因为它使第二个列表保持不变. delete
也不好,因为它删除了多重性.
member
is no good as it leaves the second list unchanged. delete
is no good either as it deletes the multiplicities.
您可以使用append
. :)它也结合了选择和删除:
You could use append
though. :) It too combines picking and removing:
perm([A|B],L):- length(L,N), between(0,N,I),length(X,I),
append(X,[A],Y), append(Y,Z,L),
append(X,Z,M), perm(B,M).
perm([],[]).