Skip to content

Instantly share code, notes, and snippets.

@barbolani
Created December 18, 2014 15:07
Show Gist options
  • Save barbolani/be0b5784bfb11c99ef44 to your computer and use it in GitHub Desktop.
Save barbolani/be0b5784bfb11c99ef44 to your computer and use it in GitHub Desktop.
Prolog - generate list permutations
% Short permutation generator permutations(L,S) is true whenever S is a permutation
% of the elements of list L
permutations([],[]).
permutations( A, [R21 | X ] ) :-
append( L, [R21 | R22], A ),
append( L, R22, X2),
permutations( X2, X).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment