PPT Slide
Permutations of a List , Using Insert
permute( [ H | T ], L ) :- permute( T, U ),
|?- permute ([1, 2, 3], Q).
permute ([1 | [2, 3]], Q) :- permute ([2, 3], U), insert (1, U, Q).
permute ([2 | [3]], U1) :- permute ([3], U2), insert (2, U2, U1)
permute ([3 | NIL], U2) :- permute (NIL, U3), insert (3, U3, U2)
permute (NIL, NIL), insert (3, NIL, U2)
permute ([2, 3], [2, 3] )
insert (1, [2, 3], [1, 2, 3])
permute ([1, 2, 3], [1, 2, 3])
Q = [1, 2, 3 ] first answer!