37 lines
900 B
Plaintext
37 lines
900 B
Plaintext
input$ = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
|
PRINT "Input: " input$
|
|
rle$ = FNencodeRLE(input$)
|
|
output$ = FNdecodeRLE(rle$)
|
|
PRINT "Output: " output$
|
|
END
|
|
|
|
DEF FNencodeRLE(text$)
|
|
LOCAL n%, r%, c$, o$
|
|
n% = 1
|
|
WHILE n% <= LEN(text$)
|
|
c$ = MID$(text$, n%, 1)
|
|
n% += 1
|
|
r% = 1
|
|
WHILE c$ = MID$(text$, n%, 1) AND r% < 127
|
|
r% += 1
|
|
n% += 1
|
|
ENDWHILE
|
|
IF r% < 3 o$ += STRING$(r%, c$) ELSE o$ += CHR$(128+r%) + c$
|
|
ENDWHILE
|
|
= o$
|
|
|
|
DEF FNdecodeRLE(rle$)
|
|
LOCAL n%, c$, o$
|
|
n% = 1
|
|
WHILE n% <= LEN(rle$)
|
|
c$ = MID$(rle$, n%, 1)
|
|
n% += 1
|
|
IF ASC(c$) > 128 THEN
|
|
o$ += STRING$(ASC(c$)-128, MID$(rle$, n%, 1))
|
|
n% += 1
|
|
ELSE
|
|
o$ += c$
|
|
ENDIF
|
|
ENDWHILE
|
|
= o$
|