RosettaCodeData/Task/Run-length-encoding/EasyLang/run-length-encoding.easy

34 lines
550 B
Plaintext

proc enc in$ . out$ .
out$ = ""
for c$ in strchars in$
if c$ = c0$
cnt += 1
else
if cnt > 0
out$ &= cnt & c0$ & " "
.
c0$ = c$
cnt = 1
.
.
out$ &= cnt & c0$
.
proc dec in$ . out$ .
out$ = ""
for h$ in strsplit in$ " "
c$ = substr h$ len h$ 1
for i to number h$
out$ &= c$
.
.
.
s$ = input
print s$
call enc s$ s$
print s$
call dec s$ s$
print s$
#
input_data
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW