[seqfan] Re: Mathematica code for trimming a sequence to the correct length

Charles Greathouse charles.greathouse at case.edu
Wed Apr 20 21:47:36 CEST 2011


I wrote a similar program some time ago in GP that would give the %S, %T,
and %U lines with the appropriate number of characters.  One nice feature is
that it would take either a vector (what Mathematica calls a List[]) or a
closure (function) so that you could skip a step if lazy.

Charles Greathouse
Analyst/Programmer
Case Western Reserve University

On Wed, Apr 20, 2011 at 1:29 PM, T. D. Noe <noe at sspectra.com> wrote:

> (If you are not a Mathematica user, please ignore, or translate this code
> to your favorite language and share.)
>
> Do you want your sequences to be the correct length when you submit a new
> sequence?  Me too.  So I wrote some code for doing it:
>
> OEISTrim[lst_List, maxLen_Integer: 260] :=
>  Module[{newLst = {}, len = 0},
>  Do[len = len + 2 + Length[IntegerDigits[term]] + Boole[term < 0];
>   If[len <= maxLen, AppendTo[newLst, term], Break[]], {term, lst}];
>  newLst]
>
> It defaults to a length of 260 characters, which seems perfect.  Example:
> the sequence of numbers 1 to 100 is trimmed by
>
> OEISTrim[Range[100]]
>
> producing a list of just the first 67 numbers.
>
> Best regards,
>
> Tony
>
> _______________________________________________
>
> Seqfan Mailing list - http://list.seqfan.eu/
>



More information about the SeqFan mailing list