pack([], []).
pack([X], [[X]]).
pack([H, T|TS], [[H]|TR]):-
H \= T,
pack([T|TS], TR).
pack([H, H|HS], [[H|TFR]|TR]):-
pack([H|HS], [TFR|TR]).
:- pack
([a
,a
,a
,a
,b
,c
,c
,a
,a
,d
,e
,e
,e
,e
],X
), write(X
).
cGFjayhbXSwgW10pLgoKcGFjayhbWF0sIFtbWF1dKS4KCnBhY2soW0gsIFR8VFNdLCBbW0hdfFRSXSk6LQogICAgSCBcPSBULAogICAgcGFjayhbVHxUU10sIFRSKS4KCnBhY2soW0gsIEh8SFNdLCBbW0h8VEZSXXxUUl0pOi0KICAgIHBhY2soW0h8SFNdLCBbVEZSfFRSXSkuCgo6LSBwYWNrKFthLGEsYSxhLGIsYyxjLGEsYSxkLGUsZSxlLGVdLFgpLCB3cml0ZShYKS4=
[[a, a, a, a], [b], [c, c], [a, a], [d], [e, e, e, e]]