[seqfan] Re: Mathematica code for trimming a sequence to the correct length
Robert Gerbicz
robert.gerbicz at gmail.com
Thu Apr 21 03:31:02 CEST 2011
2011/4/21 peter.luschny <peter.luschny at googlemail.com>
> T. D. Noe: ".. or translate this code to your
> favorite language and share."
>
> If you are not a Maple user, please ignore...
>
> OEIStrim := proc(f, offset)
> local L, n, len, fn;
> L := NULL; len := 0;
> n := `if`(whattype(f)=list,1,offset);
> do
> fn := `if`(whattype(f)=list,f[n],f(n));
> len := len + 2 + length(fn);
> if len > 260 then break fi;
> L := L,fn;
> n := n + 1;
> od;
> L end:
>
> Usage:
> OEIStrim(n -> n, 0);
>
> f := n -> n:
> OEIStrim(f, 0);
>
> F := [seq(n, n = 0..100)]:
> OEIStrim(F, ignore);
>
> _______________________________________________
>
> Seqfan Mailing list - http://list.seqfan.eu/
>
In PARI-GP:
OEISTrim(v)=L=260;len=0;w=[];for(i=1,length(v),\
len+=3+(v[i]<0);x=abs(v[i])\10;while(x,len++;x\=10);\
if(len>L,break);w=concat(w,v[i]));return(w)
try: OEISTrim(vector(100,i,i)) returns by the first 67 positive integers.
More information about the SeqFan
mailing list