




Reference: G. Brassard and P. Bratley, Algorithmics, Theory and Practice, p.186.
visit:=proc(k) local t; global v,n;
if k=n then print(v) else for t from k to n
do v:=subs({v[t]=v[k],v[k]=v[t]},v);
visit(k+1);
v:=subs({v[t]=v[k] ,v[k]=v[t] },v); od;
fi;
end;
n:=5;
v:=[1,2,3,4,5];
visit(1);