Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Run-length-encoding/REXX/run-length-encoding-1.rexx
Normal file
38
Task/Run-length-encoding/REXX/run-length-encoding-1.rexx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*REXX program encodes and displays a string by using a run─length encoding scheme. */
|
||||
parse arg input . /*normally, input would be in a file. */
|
||||
default= 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW'
|
||||
if input=='' | input=="," then input= default /*Not specified? Then use the default.*/
|
||||
encode= RLE(input) ; say ' input=' input /*encode input string; display input. */
|
||||
say 'encoded=' encode /* display run─len*/
|
||||
decode= RLD(encode); say 'decoded=' decode /*decode the run─len; display decode.*/
|
||||
if decode==input then say 'OK'; else say "¬ OK" /*display yay or nay (success/failure).*/
|
||||
exit 0 /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
err: say; say "***error*** input data isn't alphabetic:" c; say; exit 13
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RLE: procedure; parse arg x; $= /*$: is the output string (so far). */
|
||||
Lx= length(x) /*get length of the plain text string. */
|
||||
do j=1 by 0 to Lx; c= substr(x, j, 1) /*obtain a character from plain text. */
|
||||
if \datatype(c, 'M') then call err /*Character not a letter? Issue error.*/
|
||||
r= 0 /*R: is NOT the number of characters. */
|
||||
do k=j+1 to Lx while substr(x, k, 1)==c /*while characters ≡ C */
|
||||
r= r + 1 /*bump the replication count for a char*/
|
||||
end /*k*/
|
||||
j= j + r + 1 /*increment (add to) the DO loop index.*/
|
||||
if r==0 then $= $ || c /*don't use R if it is equal to zero.*/
|
||||
else $= $ || r || c /*add character to the encoded string. */
|
||||
end /*j*/; return $ /*return the encoded string to caller. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RLD: procedure; parse arg x; $= /*$: is the output string (so far). */
|
||||
Lx= length(x) /*get the length of the encoded string.*/
|
||||
do j=1 by 0 to Lx; c= substr(x, j, 1) /*obtain a character from run encoding.*/
|
||||
if \datatype(c, 'W') then do; $= $ || c; j= j + 1; iterate /*j*/
|
||||
end /* [↑] a loner char, add it to output.*/
|
||||
#= 1 /* [↓] W: use a Whole number*/
|
||||
do k=j+1 to Lx while datatype(substr(x,k,1), 'w') /*while numeric*/
|
||||
#= # + 1 /*bump the count of the numeric chars. */
|
||||
end /*k*/
|
||||
n= substr(x, j, #) + 1 /*#: the length of encoded character. */
|
||||
$= $ || copies( substr(x, k, 1), n) /*N: is now the number of characters. */
|
||||
j= j + # + 1 /*increment the DO loop index by D+1. */
|
||||
end /*j*/; return $ /*return the decoded string to caller. */
|
||||
40
Task/Run-length-encoding/REXX/run-length-encoding-2.rexx
Normal file
40
Task/Run-length-encoding/REXX/run-length-encoding-2.rexx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*REXX*/
|
||||
s='WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW'
|
||||
Say ' s='s
|
||||
enc=encode(s)
|
||||
Say 'enc='enc
|
||||
dec=decode(enc)
|
||||
Say 'dec='dec
|
||||
if dec==s Then Say 'OK'
|
||||
Exit
|
||||
|
||||
encode: Procedure
|
||||
Parse Arg s
|
||||
c=left(s,1)
|
||||
cnt=1
|
||||
ol=''
|
||||
Do i=2 To length(s)
|
||||
If substr(s,i,1)=c Then
|
||||
cnt=cnt+1
|
||||
Else Do
|
||||
Call o cnt||c
|
||||
c=substr(s,i,1)
|
||||
cnt=1
|
||||
End
|
||||
End
|
||||
Call o cnt||c
|
||||
Return ol
|
||||
|
||||
decode: Procedure
|
||||
Parse Arg s
|
||||
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
ol=''
|
||||
Do While s<>''
|
||||
p=verify(s,abc,'M')
|
||||
Parse Var s cnt =(p) c +1 s
|
||||
Call o copies(c,cnt)
|
||||
End
|
||||
Return ol
|
||||
|
||||
o: ol=ol||arg(1)
|
||||
Return
|
||||
49
Task/Run-length-encoding/REXX/run-length-encoding-3.rexx
Normal file
49
Task/Run-length-encoding/REXX/run-length-encoding-3.rexx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*REXX*/
|
||||
s='WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW'
|
||||
Say ' s='s
|
||||
enc=encode(s)
|
||||
Say 'enc='enc
|
||||
dec=decode(enc)
|
||||
Say 'dec='dec
|
||||
if dec==s Then Say 'OK'
|
||||
Exit
|
||||
|
||||
encode: Procedure
|
||||
Parse Arg s
|
||||
c=left(s,1)
|
||||
cnt=1
|
||||
ol=''
|
||||
Do i=2 To length(s)
|
||||
If substr(s,i,1)=c Then
|
||||
cnt=cnt+1
|
||||
Else Do
|
||||
If cnt=1 Then
|
||||
Call o c
|
||||
Else
|
||||
Call o cnt||c
|
||||
c=substr(s,i,1)
|
||||
cnt=1
|
||||
End
|
||||
End
|
||||
Call o cnt||c
|
||||
Return ol
|
||||
|
||||
decode: Procedure
|
||||
Parse Arg s
|
||||
abc='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
ol=''
|
||||
Do While s<>''
|
||||
p=verify(s,abc,'M')
|
||||
If pos(left(s,1),abc)>0 Then Do
|
||||
Parse Var s c +1 s
|
||||
Call o c
|
||||
End
|
||||
Else Do
|
||||
Parse Var s cnt =(p) c +1 s
|
||||
Call o copies(c,cnt)
|
||||
End
|
||||
End
|
||||
Return ol
|
||||
|
||||
o: ol=ol||arg(1)
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue