Run-length encoding: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 561: | Line 561: | ||
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW |
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW |
||
true</pre> |
true</pre> |
||
=={{header|Arturo}}== |
|||
<lang rebol>runlengthEncode: function [s][ |
|||
join map chunk split s => [&] 'x -> |
|||
(to :string size x) ++ first x |
|||
] |
|||
runlengthDecode: function [s][ |
|||
result: new "" |
|||
loop (chunk split s 'x -> positive? size match x {/\d+/}) [a,b] -> |
|||
'result ++ repeat first b to :integer join to [:string] a |
|||
return result |
|||
] |
|||
str: "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW" |
|||
encoded: runlengthEncode str |
|||
print ["encoded:" encoded] |
|||
decoded: runlengthDecode encoded |
|||
print ["decoded:" decoded] |
|||
if decoded=str -> print "\nSuccess!"</lang> |
|||
{{out}} |
|||
<pre>encoded: 12W1B12W3B24W1B14W |
|||
decoded: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW |
|||
Success!</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |