Ruud H.G. van Tol on Sat, 24 Dec 2022 18:17:24 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

veccount



Is there a more canonical way to do runlength-counting?

{ my(count(v)= my(a=List(),c=1);for(i=1,#v-1,if(v[i+1]==v[i],c++,listput(a,c);c=1));Vec(a));
  print(count([logint(2^i,3)|i<-[0..98]]));
}
[2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 2, 1]


-- Ruud