[seqfan] Mathematica code for trimming a sequence to the correct length
T. D. Noe
noe at sspectra.com
Wed Apr 20 19:29:23 CEST 2011
(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
More information about the SeqFan
mailing list