Skip to content

Instantly share code, notes, and snippets.

@trietptm
Created December 15, 2012 02:25
Show Gist options
  • Save trietptm/4290757 to your computer and use it in GitHub Desktop.
Save trietptm/4290757 to your computer and use it in GitHub Desktop.
Finding all permutations of a list(PROLOG) a snippet that lists all the possible permutations of a list
appendlist([], X, X).
appendlist([T|H], X, [T|L]) :- appendlist(H, X, L).
permutation([], []).
permutation([X], [X]) :-!.
permutation([T|H], X) :- permutation(H, H1), appendlist(L1, L2, H1), appendlist(L1, [T], X1), appendlist(X1, L2, X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment