Encode and de-code run-length encoding in Prolog with a single predicate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|encode(XS, [E|ES]) :-|
|append(XRightReversed, XLeft, XSReversed),|
|XLeft \= ,|
|expand([X|XT], [Count, X]) :- expand(XT, [SubCount, X]), succ(SubCount, Count).|
|expand(, [0, _]).|