Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
16
Task/Run-length-encoding/Picat/run-length-encoding-1.picat
Normal file
16
Task/Run-length-encoding/Picat/run-length-encoding-1.picat
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
rle(S) = RLE =>
|
||||
RLE = "",
|
||||
Char = S[1],
|
||||
I = 2,
|
||||
Count = 1,
|
||||
while (I <= S.len)
|
||||
if Char == S[I] then
|
||||
Count := Count + 1
|
||||
else
|
||||
RLE := RLE ++ Count.to_string() ++ Char.to_string(),
|
||||
Count := 1,
|
||||
Char := S[I]
|
||||
end,
|
||||
I := I + 1
|
||||
end,
|
||||
RLE := RLE ++ Count.to_string() ++ Char.to_string().
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
rle2(S) = RLE =>
|
||||
Ix = [1] ++ [I : I in 2..S.len, S[I] != S[I-1]] ++ [S.len+1],
|
||||
Diffs = diff(Ix),
|
||||
RLE = [Diffs[I].to_string() ++ S[Ix[I]].to_string() : I in 1..Diffs.len].join('').
|
||||
11
Task/Run-length-encoding/Picat/run-length-encoding-3.picat
Normal file
11
Task/Run-length-encoding/Picat/run-length-encoding-3.picat
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
rle3(S) = RLE =>
|
||||
rle3(S.tail(),S[1],1,[],RLE).
|
||||
|
||||
rle3([],LastChar,Count,RLE1,RLE) =>
|
||||
RLE = (RLE1 ++ [Count.to_string(),LastChar.to_string()]).join('').
|
||||
|
||||
rle3([C|T],LastChar,Count,RLE1,RLE) =>
|
||||
C == LastChar ->
|
||||
rle3(T,C,Count+1,RLE1,RLE)
|
||||
;
|
||||
rle3(T,C,1,RLE1++[Count.to_string()++LastChar.to_string()],RLE).
|
||||
13
Task/Run-length-encoding/Picat/run-length-encoding-4.picat
Normal file
13
Task/Run-length-encoding/Picat/run-length-encoding-4.picat
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
go =>
|
||||
S = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWA",
|
||||
println(S),
|
||||
RLE = rle3(S),
|
||||
println(rle=RLE),
|
||||
D = rl_decode(RLE),
|
||||
println(D),
|
||||
if D == S then
|
||||
println(ok)
|
||||
else
|
||||
println(not_ok)
|
||||
end,
|
||||
nl.
|
||||
14
Task/Run-length-encoding/Picat/run-length-encoding-5.picat
Normal file
14
Task/Run-length-encoding/Picat/run-length-encoding-5.picat
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
go2 =>
|
||||
_ = random2(),
|
||||
Alpha = "AB",
|
||||
Len2 = Alpha.len,
|
||||
_ = random2(),
|
||||
S = [Alpha[random(1,Len2)] : _ in 1..30_000],
|
||||
if S.len < 200 then println(s=S) end ,
|
||||
println("rle/1:"),
|
||||
time(_=rle(S)),
|
||||
println("rle2/1:"),
|
||||
time(_=rle2(S)),
|
||||
println("rle3/1:"),
|
||||
time(_=rle3(S)),
|
||||
nl.
|
||||
Loading…
Add table
Add a link
Reference in a new issue