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/Pure/run-length-encoding.pure
Normal file
15
Task/Run-length-encoding/Pure/run-length-encoding.pure
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using system;
|
||||
|
||||
encode s = strcat $ map (sprintf "%d%s") $ encode $ chars s with
|
||||
encode [] = [];
|
||||
encode xs@(x:_) = (#takewhile (==x) xs,x) : encode (dropwhile (==x) xs);
|
||||
end;
|
||||
|
||||
decode s = strcat [c | n,c = parse s; i = 1..n] with
|
||||
parse s::string = regexg item "([0-9]+)(.)" REG_EXTENDED s 0;
|
||||
item info = val (reg 1 info!1), reg 2 info!1;
|
||||
end;
|
||||
|
||||
let s = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW";
|
||||
let r = encode s; // "12W1B12W3B24W1B14W"
|
||||
decode r;
|
||||
Loading…
Add table
Add a link
Reference in a new issue