19 lines
581 B
Plaintext
19 lines
581 B
Plaintext
main :: [sys_message]
|
|
main = [Stdout (lay [inp, show enc, dec])]
|
|
where inp = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
|
|
enc = rlencode inp
|
|
dec = rldecode enc
|
|
|
|
rlencode :: [*]->[(num,*)]
|
|
rlencode xs = [(#p, hd p) | p <- chunk xs]
|
|
|
|
rldecode :: [(num,*)]->[*]
|
|
rldecode xs = concat [take n (repeat x) | (n,x) <- xs]
|
|
|
|
chunk :: [*]->[[*]]
|
|
chunk = f []
|
|
where f acc [] = [acc]
|
|
f [] (a:as) = f [a] as
|
|
f (a:acc) (a:as) = f (a:a:acc) as
|
|
f acc (a:as) = acc:f [a] as
|