Run-length encoding: Difference between revisions

m
J: document an edge case
(code sample changed to PL/pgSQL)
m (J: document an edge case)
Line 1,462:
rld '12W1B12W3B24W1B14W'
WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW</lang>
 
Note that this implementation fails for the empty case. Here's a version that fixes that:
 
<lang j>rle=: ;@(<@(":@#,{.);.1~ 2 ~:/\ (a.{.@-.{.),])</lang>
 
Other approaches include using rle ::(''"_) or rle^:(*@#) or equivalent variations on the original sentence.
 
=={{header|Java}}==
6,962

edits