June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
42
Task/Run-length-encoding/BaCon/run-length-encoding.bacon
Normal file
42
Task/Run-length-encoding/BaCon/run-length-encoding.bacon
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
FUNCTION Rle_Encode$(txt$)
|
||||
|
||||
LOCAL result$, c$ = LEFT$(txt$, 1)
|
||||
LOCAL total = 1
|
||||
|
||||
FOR x = 2 TO LEN(txt$)
|
||||
IF c$ = MID$(txt$, x, 1) THEN
|
||||
INCR total
|
||||
ELSE
|
||||
result$ = result$ & STR$(total) & c$
|
||||
c$ = MID$(txt$, x, 1)
|
||||
total = 1
|
||||
END IF
|
||||
NEXT
|
||||
|
||||
RETURN result$ & STR$(total) & c$
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION Rle_Decode$(txt$)
|
||||
|
||||
LOCAL nr$, result$
|
||||
|
||||
FOR x = 1 TO LEN(txt$)
|
||||
IF REGEX(MID$(txt$, x, 1), "[[:digit:]]") THEN
|
||||
nr$ = nr$ & MID$(txt$, x, 1)
|
||||
ELSE
|
||||
result$ = result$ & FILL$(VAL(nr$), ASC(MID$(txt$, x, 1)))
|
||||
nr$ = ""
|
||||
END IF
|
||||
NEXT
|
||||
|
||||
RETURN result$
|
||||
|
||||
END FUNCTION
|
||||
|
||||
rle_data$ = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
||||
|
||||
PRINT "RLEData: ", rle_data$
|
||||
encoded$ = Rle_Encode$(rle_data$)
|
||||
PRINT "Encoded: ", encoded$
|
||||
PRINT "Decoded: ", Rle_Decode$(encoded$)
|
||||
Loading…
Add table
Add a link
Reference in a new issue