Advertisement
Guest User

Untitled

a guest
Aug 4th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.26 KB | None | 0 0
  1. pack([],[]).
  2. pack([H], [[H]]).
  3. pack([H,H|T], R) :- append([H], T, L), pack(L, [X|Y]),
  4.                     append([H], X, P), append([P], Y, R).
  5. pack([H|T], R):- pack(T, L), append([H], L, R).
  6.  
  7. ?- pack([1,1,2,2,1,1,1,3],R).
  8. R = [[1|1], [2|2], [1, 1|1], [3]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement