A specification of elements in a list as a list of pairs giving the element and number of times it occurs in a run. For example, given the list , the run-length encoding
is {
,
,
,
,
,
,
}. Run-length encoding can be implemented in the Wolfram
Language as:
RunLengthEncode[x_List] :=
{First[#], Length[#]}& /@ Split[x]
To recover the original list, repeat each element by the corresponding run length and concatenate the resulting lists:
RunLengthDecode[pairs_List] :=
Catenate[ConstantArray @@@ pairs]