Run-length encoding: Difference between revisions
Content deleted Content added
→{{header|Lasso}}: Adding Lasso RLE Example |
→{{header|REXX}}: made incrementing of the DO loop index more idiomatic, changed whitespade and comments, simplified encoding. -- ~~~~ |
||
Line 2,718: | Line 2,718: | ||
The task (input) rule was relaxed a bit as this program accepts upper- and lowercase input. |
The task (input) rule was relaxed a bit as this program accepts upper- and lowercase input. |
||
===encoding=== |
===encoding=== |
||
<lang rexx>/*REXX program encodes string by using a run-length scheme |
<lang rexx>/*REXX program encodes a string by using a run-length scheme. */ |
||
parse arg x |
parse arg x . /*normally, input would be a file*/ |
||
/*═══ arg x . ═══*/ /*◄── use if X must be uppercase.*/ |
|||
def='WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW' |
def= 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW' |
||
if x |
if x='' then x=def /*No input? Then use the default.*/ |
||
Lx=length(x) /*get the length of the X string.*/ |
Lx=length(x) /*get the length of the X string.*/ |
||
y= /*Y is the output string (so far)*/ |
y= /*Y is the output string (so far)*/ |
||
do j=1 |
do j=1 by 0 to Lx /*J is incremented (below). */ |
||
c=substr(x,j,1) /*pick a character, check for err*/ |
c=substr(x,j,1) /*pick a character, check for err*/ |
||
if \datatype(c,' |
if \datatype(c,'M') then do; say "error!: data isn't alphabetic:" c; exit 13; end |
||
r=0 /*R is NOT the number of chars. */ |
r=0 /*R is NOT the number of chars. */ |
||
⚫ | |||
⚫ | |||
⚫ | |||
end /*k*/ |
|||
⚫ | |||
end /*k*/ |
|||
if r==0 then r= /*don't use R if R is zero.*/ |
|||
Y = Y || r || c /*add it to the encoded string.*/ |
|||
⚫ | |||
⚫ | |||
end /*j*/ |
end /*j*/ |
||