Run-length encoding: Difference between revisions

no edit summary
(Run-length encoding en BASIC256)
No edit summary
Line 2,849:
return ret
end</lang>
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module RLE_example {
inp$="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
Print "Input: ";inp$
Function RLE$(r$){
Function rle_run$(&r$) {
if len(r$)=0 then exit
p=1
c$=left$(r$,1)
while c$=mid$(r$, p, 1) {p++}
=format$("{0}{1}",p-1, c$)
r$=mid$(r$, p)
}
def repl$
while len(r$)>0 {repl$+=rle_run$(&r$)}
=repl$
}
RLE_encode$=RLE$(inp$)
Print "RLE Encoded: ";RLE_encode$
Function RLE_decode$(r$) {
def repl$
def long m, many=1
while r$<>"" and many>0 {
many=val(r$, "INT", m)
repl$+=string$(mid$(r$, m, 1), many)
r$=mid$(r$,m+1)
}
=repl$
}
RLE_decode$=RLE_decode$(RLE_encode$)
Print "RLE Decoded: ";RLE_decode$
Print "Checked: ";RLE_decode$=inp$
}
RLE_example
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
Input: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
RLE Encoded: 12W1B12W3B24W1B14W
RLE Decoded: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
Checked: True
</pre >
=={{header|Mathematica}}==
Custom functions using Map, Apply, pure functions, replacing using pattern matching, delayed rules and other functions:
Anonymous user