Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Run-length-encoding/PARI-GP/run-length-encoding.parigp
Normal file
31
Task/Run-length-encoding/PARI-GP/run-length-encoding.parigp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
rle(s)={
|
||||
if(s=="", return(s));
|
||||
my(v=Vec(s),cur=v[1],ct=1,out="");
|
||||
v=concat(v,99); \\ sentinel
|
||||
for(i=2,#v,
|
||||
if(v[i]==cur,
|
||||
ct++
|
||||
,
|
||||
out=Str(out,ct,cur);
|
||||
cur=v[i];
|
||||
ct=1
|
||||
)
|
||||
);
|
||||
out
|
||||
};
|
||||
elr(s)={
|
||||
if(s=="", return(s));
|
||||
my(v=Vec(s),ct=eval(v[1]),out="");
|
||||
v=concat(v,99); \\ sentinel
|
||||
for(i=2,#v,
|
||||
if(v[i]>="0" && v[i]<="9",
|
||||
ct=10*ct+eval(v[i])
|
||||
,
|
||||
for(j=1,ct,out=Str(out,v[i]));
|
||||
ct=0
|
||||
)
|
||||
);
|
||||
out
|
||||
};
|
||||
rle("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
|
||||
elr(%)
|
||||
Loading…
Add table
Add a link
Reference in a new issue