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.

Scoring

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.

Example

Here's a valid answer in Java 8:

(int a) -> {
    for (int i = 0; i < 20; i++) {
        System.out.println(a==27?i+1:i*i); 
    }
};

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

Note

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.

share|improve this question
    
Can we write it so that it takes the leading 0's? – TrojanByAccident 13 hours ago
    
WHOO! A challenge on OEIS! – JungHwan Min 12 hours ago
1  
@TrojanByAccident if your idea is to connect to OEIS, that's not allowed on PPCG – Nathan Merrill 12 hours ago
    
@NathanMerrill I wasn't sure if that counted in this instance – TrojanByAccident 12 hours ago
    
Are functions allowed? – xnor 12 hours ago

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.

n=input()-16729
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:

c=input()
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.

share|improve this answer
    
haha, nice one! – Maltysen 12 hours ago
    
also, shorter: lambda n:range(0,(n-8582)*20,n-8582) – Maltysen 12 hours ago
    
@Maltysen Spec said program, so I went with that. I'll ask. – xnor 12 hours ago
2  
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. – Mitchell Spector 6 hours ago
1  
@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.) – Mitchell Spector 6 hours ago

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

share|improve this answer
3  
Heh, cute idea! – Jonathan Allan 8 hours ago
    
@JonathanAllan Thanks! – Mitchell Spector 8 hours ago

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).

share|improve this answer

Mathematica, 39 173 189 sequences

If[l=0~Range~19;#<4^7,l,If[#<3^9,#&@@RealDigits[Log[j=16627;#-j+If[#<j,49.5,4]],10,20],#-22956-l]]&

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)
share|improve this answer

Jelly, 1127 sequences

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

0x20
_21004$ȷ20:DU¢oU
<22ȷ3a>5‘µĿ

TryItOnline!

The main function is at the bottom. 22ȷ3 is 22000, a is the logical and function and is increment, so <22ȷ3a>5‘ results in 2 if the input is between 6 and 21999 inclusive and 1 otherwise. µ is a monadic chain separation to pass that result into the next instruction, the quick Ŀ which calls the link at that index (1-based). Link 1 is 0x20 which is a list of 20 zeros. Link 2 is...

_21004$ȷ20:DU¢oU - Link 2: n
       ȷ20       - 1e20
      $          - last two links as a monad
_21004           - subtract 21,004 from n
          :      - integer divide
           D     - decimal list
            U    - reverse
             ¢   - last link (1) as a monad - gets a list of 20 zeros
              o  - logical or - effectively pad to 20 with zeros
               U - reverse back again
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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