June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
18
Task/Run-length-encoding/Factor/run-length-encoding.factor
Normal file
18
Task/Run-length-encoding/Factor/run-length-encoding.factor
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
USING: io kernel literals math.parser math.ranges sequences
|
||||
sequences.extras sequences.repeating splitting.extras
|
||||
splitting.monotonic strings ;
|
||||
IN: rosetta-code.run-length-encoding
|
||||
|
||||
CONSTANT: alpha $[ CHAR: A CHAR: Z [a,b] >string ]
|
||||
|
||||
: encode ( str -- str )
|
||||
[ = ] monotonic-split [ [ length number>string ] [ first ]
|
||||
bi suffix ] map concat ;
|
||||
|
||||
: decode ( str -- str )
|
||||
alpha split* [ odd-indices ] [ even-indices
|
||||
[ string>number ] map ] bi [ repeat ] 2map concat ;
|
||||
|
||||
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
||||
"12W1B12W3B24W1B14W"
|
||||
[ encode ] [ decode ] bi* [ print ] bi@
|
||||
Loading…
Add table
Add a link
Reference in a new issue