RosettaCodeData/Task/Run-length-encoding/Picat/run-length-encoding-3.picat
2023-07-01 13:44:08 -04:00

11 lines
318 B
Text

rle3(S) = RLE =>
rle3(S.tail(),S[1],1,[],RLE).
rle3([],LastChar,Count,RLE1,RLE) =>
RLE = (RLE1 ++ [Count.to_string(),LastChar.to_string()]).join('').
rle3([C|T],LastChar,Count,RLE1,RLE) =>
C == LastChar ->
rle3(T,C,Count+1,RLE1,RLE)
;
rle3(T,C,1,RLE1++[Count.to_string()++LastChar.to_string()],RLE).