Run-length encoding: Difference between revisions

Content added Content deleted
(adding maxima)
Line 1,644: Line 1,644:
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
True</lang>
True</lang>
And alternate solution:
<lang Mathematica>RunLengthEncode[s_String]:=StringJoin[{ToString[Length[#]]<>First[#]} &/@Split[StringSplit[s,""]]]
RunLengthDecode[s_String]:=StringJoin[Table[#[[2]],{ToExpression[#[[1]]]}]&/@(StringSplit[s,x:_?LetterQ:>x]//Partition[#,2]&)]</lang>
This second encode function is adapted from the MathWorld example.


=={{header|Maxima}}==
=={{header|Maxima}}==