fork(11) download
  1. pack([], []).
  2.  
  3. pack([X], [[X]]).
  4.  
  5. pack([H, T|TS], [[H]|TR]):-
  6. H \= T,
  7. pack([T|TS], TR).
  8.  
  9. pack([H, H|HS], [[H|TFR]|TR]):-
  10. pack([H|HS], [TFR|TR]).
  11.  
  12. :- pack([a,a,a,a,b,c,c,a,a,d,e,e,e,e],X), write(X).
Success #stdin #stdout #stderr 0.02s 6160KB
stdin
Standard input is empty
stdout
[[a, a, a, a], [b], [c, c], [a, a], [d], [e, e, e, e]]
stderr