tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
15
Task/Run-length-encoding/Forth/run-length-encoding-1.fth
Normal file
15
Task/Run-length-encoding/Forth/run-length-encoding-1.fth
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
variable a
|
||||
: n>a (.) tuck a @ swap move a +! ;
|
||||
: >a a @ c! 1 a +! ;
|
||||
: encode ( c-addr +n a -- a n' )
|
||||
dup a ! -rot over c@ 1 2swap 1 /string bounds ?do
|
||||
over i c@ = if 1+
|
||||
else n>a >a i c@ 1 then
|
||||
loop n>a >a a @ over - ;
|
||||
|
||||
: digit? [char] 0 [ char 9 1+ literal ] within ;
|
||||
: decode ( c-addr +n a -- a n' )
|
||||
dup a ! 0 2swap bounds ?do
|
||||
i c@ digit? if 10 * i c@ [char] 0 - + else
|
||||
a @ over i c@ fill a +! 0 then
|
||||
loop drop a @ over - ;
|
||||
3
Task/Run-length-encoding/Forth/run-length-encoding-2.fth
Normal file
3
Task/Run-length-encoding/Forth/run-length-encoding-2.fth
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s" WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
||||
here 1000 + encode here 2000 + decode cr 3 spaces type
|
||||
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
|
||||
Loading…
Add table
Add a link
Reference in a new issue