PERL   19

permutations

Guest on 16th August 2022 01:05:58 AM

  1. % permutations.pl
  2. % A Prolog program for finding all permutations of a list.
  3. % S. Tanimoto, Spring .
  4.  
  5. remove(H, [H|T], T).
  6. remove(A, [H|T], [H|B]) :- remove(A, T, B).
  7.  
  8. permutation([], []).
  9. permutation([H|T], X) :- remove(H, X, Y), permutation(T, Y).
  10.  
  11. % permutation(X, [fee,fie,foe,foo]).

Raw Paste


Login or Register to edit or fork this paste. It's free.