Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

permutation list

Status
Not open for further replies.

xristiana

Programmer
Oct 23, 2010
48
GR
Hello to everyone,
I am studying from a prolog tutorial, but I have stuck in a programm, and can't figure it out at all. It's the perm predicate, I think it's in the prolog or sth, it's definition is this(with the definition of takeout too that it uses):
takeout(X,[X|R],R).
takeout(X,[F|R],[F|S]) :- takeout(X,R,S).
perm([X|Y],Z) :- perm(Y,W), takeout(X,Z,W).
perm([],[]).
So, I ran it on Swi-prolog, and it has 4 answers I think. Even when I put the tracer, I couldn't get what it did. :S
I understand how the first solution comes out, but not the others. Please, can anyone help? I 'm stuck and I won't be able to understand the others....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top