insert(X, XS, [X|XS]).
insert(X, [Y|YS], [Y, ZS]) :- insert(X, YS, ZS).

perm([],[]).
perm(XS,[Y|YS]) :- append(V,[Y|U],XS), append(V,U,W), perm(W,YS).
