The On-Line Encyclopedia of Integer Sequences (OEIS) is an online database of integer sequences. It contains nearly 280000 sequences of mathematical interest.

Examples of sequences:

Your task is to write a program or function that displays as many OEIS sequences as you can, with a source code of 100 bytes maximum. Your program should accept as input the sequence id (without the prepending A and the zeroes), and output the 20 first numbers in that sequence.

You are not allowed to fetch the data directly from the OEIS website; all sequences must be computed by your code.


Score is the number of OEIS sequences the program can display. Answers will have to list the IDs of the sequences recognised by their program.


Here's a valid answer in Java 8:

(int a) -> {
    for (int i = 0; i < 20; i++) {

This program can display the positive integers (A000027 - input 27) and the squares (A000290 - input 290), thus its score is 2.


Please avoid scraping the whole OEIS website :-) you can download the sequence names (about 3 megs) or sequence values (about 9 megs). Note that this download is covered by the OEIS End-User License Agreement.

  • \$\begingroup\$ Can we write it so that it takes the leading 0's? \$\endgroup\$ Jan 18, 2017 at 2:31
  • 3
    \$\begingroup\$ WHOO! A challenge on OEIS! \$\endgroup\$ Jan 18, 2017 at 2:34
  • 1
    \$\begingroup\$ @TrojanByAccident if your idea is to connect to OEIS, that's not allowed on PPCG \$\endgroup\$ Jan 18, 2017 at 2:36
  • \$\begingroup\$ @NathanMerrill I wasn't sure if that counted in this instance \$\endgroup\$ Jan 18, 2017 at 2:38
  • \$\begingroup\$ Are functions allowed? \$\endgroup\$
    – xnor
    Jan 18, 2017 at 2:41

9 Answers 9


Python 2, 875 sequences

print', '.join('%020d'%(10**20/(input()-21004)))

Works for 875 of the sequences 21016 (decimal digits of 1/12) through 21999 (decimal digits of 1/995).

I found this chunk with the sophisticated search algorithm of haphazardly typing in sequence id's by hand. Some of the sequences in the range are not of this format and appear elsewhere (thanks to Mitchell Spector for pointing this out). For example, 21021 is not the expansion of 1/17.

Even with the interruptions, the sequences for 1/n appear as id n+21004. The remainder is not shifted, but the missing sequences appear elsewhere. For example, 1/17 appears as 7450.

I counted the ones that match using a downloaded copy of the sequence names.

A different block gives 848 sequences from 16742 to 17664.

for i in range(20):k=n/12;a=int((8*k+1)**.5/2+.5);print(a*i+k-a*(a-1)/2)**(n%12+1)

These all have form n -> (a*n+b)^c, where 2≤a≤12, 0≤b<a, 1≤c≤12. The code extracts the coefficients via inverting triangular numbers and moduli. As before, not all sequences in the range match. If these two expressions could fit in 100 bytes, it would give 1723 sequences.

Promising chunks:

  • 1929 matching sequences: 41006 through 42397, numerators and denominators of continued fraction convergents.
  • ~3300 matching sequences: 147999 to 151254: counts of walks on Z^3, if you can find how the vector lists are ordered.

Here are categories for other potential chunks, via grouping the OEIS sequence names by removing all numbers (digits, minus sign, decimal point). They are sorted by number of appearances.

3010    Number of walks within N^ (the first octant of Z^) starting at (,,) and consisting of n steps taken from {(, , ), (, , ), (, , ), (, , ), (, , )}
2302    Number of reduced words of length n in Coxeter group on  generators S_i with relations (S_i)^ = (S_i S_j)^ = I
979     Primes congruent to  mod 
969     Numerators of continued fraction convergents to sqrt()
967     Denominators of continued fraction convergents to sqrt()
966     Continued fraction for sqrt()
932     Decimal expansion of /
894     Duplicate of A
659     Partial sums of A
577     Divisors of 
517     Inverse of th cyclotomic polynomial
488     Expansion of /((x)(x)(x)(x))
480     Decimal expansion of th root of 
471     Number of nX  arrays with each element x equal to the number its horizontal and vertical neighbors equal to ,,,, for x=,,,,
455     First differences of A
448     Decimal expansion of log_ ()
380     Numbers n such that string , occurs in the base  representation of n but not of n+
378     Erroneous version of A
375     Numbers n such that string , occurs in the base  representation of n but not of n
340     Numbers n with property that in base  representation the numbers of 's and 's are  and , respectively

35 sequences:

for n in range(20):print[(c-1010)**n,(c-8582)*n][c>2e3]

Works from 8585 (multiples of 3) through 8607 (multiples of 25), and 1018 (powers of 8) through 1029 (powers of 19). Conveniently, these are all in one chunk ordered by id.

This uses only 65 of the 100 allowed bytes and isn't fully golfed yet, so I'll look for another nice chunk.

  • \$\begingroup\$ haha, nice one! \$\endgroup\$
    – Maltysen
    Jan 18, 2017 at 2:37
  • \$\begingroup\$ also, shorter: lambda n:range(0,(n-8582)*20,n-8582) \$\endgroup\$
    – Maltysen
    Jan 18, 2017 at 2:40
  • \$\begingroup\$ @Maltysen Spec said program, so I went with that. I'll ask. \$\endgroup\$
    – xnor
    Jan 18, 2017 at 2:40
  • 2
    \$\begingroup\$ Good idea, but I don't think the range 21016-21999 consists entirely of reciprocals. For example, A21021 is 1, 33, 727, 13365, 221431, 3428733, ..., not the decimal digits of 1/17. I haven't checked to see which sequences are reciprocals and which ones aren't. \$\endgroup\$ Jan 18, 2017 at 8:32
  • 1
    \$\begingroup\$ @xnor However many matches you get, you can combine it with my answer to add another 252 to the count: if the input is not in the range 21016-21999, output 20 0's. (None of my 252 sequences lie in that range.) \$\endgroup\$ Jan 18, 2017 at 8:46

Bash + coreutils, 252 sequences

yes 0|head -20

Try it online!

Works on 252 OEIS sequences: A000004, A006983, A011734, A011735, A011736, A011737, A011738, A011739, A011740, A011741, A011742, A011743, A011744, A011745, A023975, A023976, A025438, A025439, A025443, A025444, A025466, A025469, A034422, A034423, A034427, A034429, A034432, A034435, A034437, A034438, A034439, A034441, A034443, A034445, A034447, A034449, A034450, A034451, A034452, A034453, A034454, A034455, A034456, A034457, A034458, A034459, A034461, A034462, A034464, A034465, A034466, A034467, A034468, A034469, A034471, A034473, A034475, A034476, A034477, A034479, A034480, A034481, A034482, A034483, A034484, A034485, A034486, A034487, A034489, A034490, A034492, A034493, A034495, A034497, A034498, A034499, A034500, A034501, A034502, A034503, A034504, A034505, A034506, A034507, A034508, A034509, A034510, A034511, A034512, A034514, A034515, A034516, A034518, A034519, A034520, A034521, A034522, A034523, A034525, A034526, A034527, A034528, A034529, A034530, A034531, A034532, A034533, A034534, A034535, A034536, A034537, A034538, A034539, A034540, A034541, A034542, A034543, A034544, A034545, A034546, A034547, A034548, A034549, A034550, A034551, A034552, A034553, A034554, A034555, A034556, A034557, A034558, A034559, A034560, A034561, A034562, A034563, A034564, A034565, A034566, A034567, A034568, A034569, A034570, A034571, A034572, A034573, A034574, A034575, A034576, A034577, A034578, A034579, A034580, A034581, A034582, A036861, A047752, A052375, A055967, A061858, A065687, A066035, A067159, A067168, A070097, A070202, A070204, A070205, A070206, A072325, A072769, A076142, A082998, A083344, A085974, A085982, A086007, A086015, A089458, A093392, A094382, A105517, A108322, A111855, A111859, A111898, A111899, A112802, A122180, A129947, A137579, A159708, A161277, A161278, A161279, A161280, A165766, A167263, A178780, A178798, A180472, A180601, A181340, A181735, A184946, A185037, A185203, A185237, A185238, A185245, A185246, A185255, A185264, A185284, A191928, A192541, A197629, A198255, A200214, A206499, A210632, A212619, A217148, A217149, A217151, A217155, A217156, A228953, A230533, A230686, A235044, A235358, A236265, A236417, A236460, A238403, A243831, A243832, A243833, A243834, A243835, A243836, A248805, A250002, A256974, A260502, A264668, A276183, A277165, A280492, A280815

  • 5
    \$\begingroup\$ Heh, cute idea! \$\endgroup\$ Jan 18, 2017 at 6:35

CJam (2182 2780 3034 sequences)


This gives correct answers for the inclusive ranges

  • [A040000, A040003], [A040005, A040008], [A040011, A040013], A040015, [A040019, A040022], A040024, [A040029, A040033], A040035, A040037, [A040041, A040043], A040048, A040052, [A040055, A040057], A040059, A040063, [A040071, A040074], A040077, A040080, [A040090, A040091], [A040093, A040094], A040097, A040099, [A040109, A040111], A040118, A040120, [A040131, A040135], A040137, A040139, [A040142, A040143], A040151, [A040155, A040157], A040166, A040168, [A040181, A040183], [A040185, A040968]
  • [A041006, A041011], [A041014, A042937]
  • A006983, [A011734, A011745], [A023975, A023976], [A025438, A025439], [A025443, A025444], A025466, A025469, [A034422, A034423], A034427, A034429, A034432, A034435, [A034437, A034439], A034441, A034443, A034445, A034447, [A034449, A034459], [A034461, A034462], [A034464, A034469], A034471, A034473, [A034475, A034477], [A034479, A034487], [A034489, A034490], [A034492, A034493], A034495, [A034497, A034512], [A034514, A034516], [A034518, A034523], [A034525, A034582], A036861, A047752, A052375, A055967, A061858, A065687, A066035, A067159, A067168, A070097, A070202, A070204, [A070205, A070206], A072325, A072769, A076142, A082998, A083344, A085974, A085982, A086007, A086015, A089458, A093392, A094382, A105517, A108322, A111855, A111859, [A111898, A111899], A112802, A122180, A129947, A137579, A159708, [A161277, A161280], A165766, A167263, A178780, A178798, A180472, A180601, A181340, A181735, A184946, A185037, A185203, [A185237, A185238], [A185245, A185246], A185255, A185264, A185284, A191928, A192541, A197629, A198255, A200214, A206499, A210632, A212619, [A217148, A217149], A217151, [A217155, A217156], A228953, A230533, A230686, A235044, A235358, A236265, A236417, A236460, A238403, [A243831, A243836], A248805, A250002, A256974, A260502, A264668, A276183, A277165, A280492, A280815

The A040??? sequences correspond to the continued fractions of non-rational square roots from sqrt(2) to sqrt(1000) (with the gaps corresponding to ones which appear earlier in OEIS, but conveniently filled with random sequences). The A041??? sequences correspond to the numerators and denominators of the continued fraction convergents for non-rational square roots from sqrt(6) to sqrt(1000) (with the gap corresponding to sqrt(10), at A005667 and A005668). The other assorted sequences have zeroes for their first twenty values.

The answer ports elements of two earlier answers of mine in GolfScript:

Many thanks to xnor for the short closed form x -> x + round(sqrt(x)) mapping sequence offsets to the value to sqrt. The savings over my previous calculation (generating the list of non-squares and selecting by index) provided enough to have an all-zero fallback for most out-of-range indices.

  • \$\begingroup\$ Might it be useful that the n'th non-square is given by n + round(sqrt(n))? \$\endgroup\$
    – xnor
    Jan 21, 2017 at 11:22
  • \$\begingroup\$ @xnor, nice one. I tried to find a nice formula with sqrt(n) but it didn't occur to me to round to nearest rather than down. That gives an immediate three byte saving, which isn't quite enough to add a fallback but keeps the hope alive. \$\endgroup\$ Jan 21, 2017 at 11:40

Python (with sympy), 144 146 sequences

import sympy
f=lambda a,M=16627:[int(c)for c in str(sympy.log((a<M)*46.5+4+a-M).n(20))if'.'<c][-20:]

The function f works for the 146 sequences A016578 through A016723 inclusive.

All of these are output by the test harness at repl.it.

The 49 sequences A016578 through A016626 inclusive are the decimal expansions of log(3/2), log(5/2), log(7/2), ..., log(99/2).

The 97 sequences A016627 through A016723 inclusive are the decimal expansions of log(4), log(5), log(6), ..., log(100).

The first two of the 49 start at the first decimal place since the log values for them are less than 1, so the [-20:] takes the trailing 20 decimal places of the result of the call to ...n(20) which gets 20 significant figures. The if'.'<c filters out the decimal place character, and the int(c) casts each remaining digit character to an integer (although maybe not necessary).


Jelly, 1127 1975 sequences

-- this currently combines the findings of xnor and Mitchell Spector, but still has some room for growth at 78 bytes. Go give them some credit!




The 1975 sequences are:

  • the 252 that start with twenty zeros (the behaviour for input outside of [16000,21999]);
  • the 848 sequences lying in the range 16742 to 17664 that match the (a*n+b)**c formula (the behaviour for input in [16000,17999]); and
  • the 875 sequences lying in the range 21016 to 21999 that match the decimal expansion of 1/n (the behaviour for input in [18000,21999]).


0x20 - Link 1, TwentyZeros: no arguments
0    - zero
  20 - twenty
 x   - repeat

_21004µȷ20:DU¢oU - Link 2, DecimalExpansionOfReciprocal: oeisIndexNumber
      µ          - monadic chain separation
       ȷ20       - 1e20
_21004           - subtract 21004 from oeisNumber to get the n value
          :      - integer division, i.e. 1e20 // n
           D     - decimal list
            U    - reverse
             ¢   - call last link (1) as a nilad, i.e. get twenty zeros
              o  - logical or, i.e. pad the right of the reversed list to twenty with zeros
               U - reverse again

20Ḷ×⁸+µ*þ12 - Link 3, BlockOf12abcFormulaResults: a, b
20Ḷ         - lowered range of 20 [0,1,...,19] i.e. the values of n in (a*n+b)**c
    ⁸       - left argument, a
   ×        - multiply
     +      - add b
      µ     - monadic chain separation
        þ12 - outer product with [1,2,...,12] of... i.e. the values of c in (a*n+b)**c
       *    -     exponentiation

11R‘µẋ`€F$ç"Ḷ€F$;/ - link 4, AllabcFormulaResults: no aguments
11R                - range of 11 [1,2,...,11]
   ‘               - increment   [2,3,...12] i.e. the values of a in (a*n+b)**c
    µ              - monadic chain separation
         $         - last two links as a monad
     ẋ`€           - repeat list with repeated arguments for €ach [[2,2],[3,3,3],...,[12,12,12,12,12,12,12,12,12,12,12,12]]
        F          - flatten into one list
               $   - last two links as a monad
            Ḷ€     - lowered range of €ach [[0,1],[0,1,2],...,[0,1,2,3,4,5,6,7,8,9,10,11]]
              F    - flatten into one list
          ç"       - zip with (") last link (3) as a dydad (ç) i.e. get all the results
                 / - reduce with
                ;  - concatenation i.e. make the list of lists of lists one list of lists.

_108ị¢ - Link 5, abcFormulaResult: oeisIndexNumber
_108   - subtract 108 from the oeisNumber (indexes in Jelly are modular and there are 924 entries, this is shorter than _16740)
     ¢ - call last link (4) as a nilad
    ị  - index into i.e. get the one relevant result of 20 terms

 - Link 6, an empty link (cheaper in bytes than the %6 alternative in the main link)

“æÑØ‘×ȷ3¤>J×$S‘µĿ - Main link: oeisIndexNumber           e.g. 1-15999; 16000-17999; 18000-21999; 22000+
        ¤         - nilad followed by link(s) as a nilad
“æÑØ‘             - codePage indexes [22,16,18]
      ȷ3          - 1e3
     ×            - multiply [22000,16000,18000]
         >        - greater than (vectorises)            e.g. [1,1,1]; [1,0,1];     [1,0,0];     [0,0,0]
            $     - last two links as a monad
          J       - range(length) [1,2,3]
           ×      - multiply                             e.g. [1,2,3]; [1,0,3];     [1,0,0];     [0,0,0]
             S    - sum                                  e.g. 6;       4;           1;           0
              ‘   - increment                            e.g. 7;       5;           2;           1
               µ  - monadic chain separation
                Ŀ - call link(index) as a monad with the oeisIndexNumber
                        link indexing is 1-based and modular so 7 calls link 1
              ><        hence the empty link 6 replacing a %6 here

Mathematica, 39 173 189 sequences


Inspired by Jonathan Allan's answer.

Works for:

  • 1477, 2837, 4830, and 8554 (the first 20 terms of these are {0, 1, 2, ... , 19})
  • 16578 to 16626 (decimal expansion of log(3/2), decimal expansion of log(5/2), ... decimal expansion of log(99/2))
  • 16627 to 16723 (decimal expansion of log(4), decimal expansion of log(5), ... decimal expansion of log(100))
  • 22958 to 22996 (2-n, 3-n, ... 40-n)

CJam, 1831 sequences


This gives correct output for 199 sequences beginning 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 and all sequences in the inclusive ranges [A168680, A169579] and [A170000, A170731]. The bulk of it deals with those two ranges, with a fallback for all-zeroes before the start of the first range.

The two ranges in question have the form

Number of reduced words of length \$n\$ in Coxeter group on \$P\$ generators \$S_i\$ with relations \$(S_i)^2 = (S_i S_j)^Q = I\$

for values of \$P\$ ranging from \$3\$ to \$50\$ and values of \$Q\$ ranging from \$17\$ to \$50\$. Their generating functions are given in a thoroughly inefficient manner: I found it useful to multiply numerators and denominators by \$(t - 1)\$ to give g.f. $$\frac{t^{Q+1} + t^Q - t - 1}{\frac12(P-2)(P-1) t^{Q+1} - \frac12(P-2)(P+1) t^Q + (P-1)t - 1}$$ although for golfing purposes I'm actually working with \$R = P + 3\$.


Batch, 62 sequences

@for /l %%i in (1,1,20)do @set/a"n=(n=22956-%1)*(n>>=16)+%%i*(n|%1-8582)"&call echo %%n%%

Just implementing one block of sequences was hard, but I managed two in 89 bytes! Explanation: For a parameter %1 of 8585-8607, 22956-%1>>16 returns zero, causing the (22956-%1) expression to be ignored and we end up multiplying the loop variable by 3-25 respectively, while for a parameter of 22958-22996 it returns minus one causing the expression to be negated, while the n| causes the multiplication factor to be replaced with minus one effectively subtracting the loop variable.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.