Disclaimer: This is heavily inspired by "Polyglot the OEIS!" but fixes the problem that lead to closure (see the output section) and was re-posted as to not invalidate answers.


We all know and love the on-line encyclopedia of integer sequences (OEIS). So what if we made an off-line version of the interesting sequences? Well, that would be kinda too easy, wouldn't it and how would you select a sequence with our standard interface!? No. We need an easier solution to this. A polyglot!


Your input will be a non-negative integer n.


Your output will either be

  • The n-th entry of an OEIS sequence OR
  • The first n entries of an OEIS sequence.

You may take the index to be 1-based or 0-based as you prefer.

To not make this question a duplicate of The versatile integer printer constant sequences are banned. This should also increase the difficulty level of submissions and avoid "boring" solutions ;)

A sequence is non-constant if there exist two sequence members that are unequal.

Uhm, so where is the Challenge?

You have to polyglot the above functionality. That is if you support languages A, B and C all must implement different OEIS sequences. The choice of sequence is not limited except that you need different ones for all languages.

That is, if you run the provided program in language A, then sequence X shall be generated, if you run the provided program in language B, then sequence Y shall be generated (with X!=Y) and if you run the provided program in language C, then sequence Z shall be generated (with X!=Z && Y!=Z).

Who wins?

The answer with the most sequence/language pairs wins. First tie-breaker is code-size (in bytes) with lower being better. Second tie-breaker is submission time with earlier being better.

Any final Words / Rules?

  • You must declare which language will generate which sequence.
  • Standard I/O rules apply.
  • If different encodings are used between languages, both programs must use the same byte-sequence.
  • Language (Python 2/3) revisions do count as different languages. Different implementations of a language (such as Browser JS vs Node.js) also count as different languages.
  • Standard loopholes apply.
  • 4
    \$\begingroup\$ This post was done in accordance to this Meta Q&A. \$\endgroup\$
    – SEJPM
    Commented Aug 14, 2017 at 18:28
  • \$\begingroup\$ Can different languages have different indexing? \$\endgroup\$
    – Stephen
    Commented Aug 14, 2017 at 20:31
  • 2
    \$\begingroup\$ @StepHen yes they can. \$\endgroup\$
    – SEJPM
    Commented Aug 14, 2017 at 20:32

6 Answers 6


3 languages (1 byte) - Pyth (A001477), MATL (A000027), Braingolf (A000217)



Q does the following:

  • In MATL, it means + 1, so it basically evaluates to input + 1.

  • In Pyth, it means input, so it just outputs the input.

  • In Braingolf, it is the built-in for triangular numbers.


Pyth can be replaced by any of the following languages: GolfScript, Pyke, Brachylog or Brain-Flak.

  • 1
    \$\begingroup\$ well you certainly picked the right languages for this one +1 :P \$\endgroup\$
    – hyper-neutrino
    Commented Aug 14, 2017 at 20:35
  • 1
    \$\begingroup\$ @HyperNeutrino I just ported my answer from there, but I chose very good languages back then, so yeah :P - Thanks! \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 14, 2017 at 20:36
  • 1
    \$\begingroup\$ Remember, this is number of languages, not code-golf :P \$\endgroup\$
    – Stephen
    Commented Aug 14, 2017 at 21:22
  • \$\begingroup\$ @StepHen I think 3 is reasonable. \$\endgroup\$
    – Mr. Xcoder
    Commented Aug 14, 2017 at 21:24

10 languages, 122 bytes

print (0 and gets.to_i-1 or int(input())**(2+(1/2>0)));quit()#⎚I±N»
# x

I definitely can add a bunch more. 1-indexed unless otherwise specified.

Note that I may not be up-to-date on TIO links when I'm sure newer changes didn't affect older programs - you can test them if you want to, but copying 10+ new TIO links every time I make a change gets tiring after a bit. I'll copy new ones every 5 updates or so.

cQuents v0, A000007

Relevant code: #|A=1:0;

#|A catches the input and is there for Python comments. =1 means the first item is 1, :0 mean the rest are 0, outputs the nth term given input n. cQuents v0 has a weird bug/feature that when an unexpected but valid token, such as ;, is read, it causes parsing to end.

Try it online!

PingPong, A001478

Relevant code: #|A=1:0;~@

Outputs via exit code. 0-indexed.

# skips the next char. = does nothing here. 1 pushes 1, and : prints 1 to STDOUT. 0 pushes 0. ) does nothing. ; pushes input, ~ pops and pushes -n-1. @ terminates. The exit code is the top of the stack.

Try it online!

axo, A001477

Relevant code: }{\

0-indexed. } reads and pushes an integer from STDIN (requires trailing newline for some reason), { prints an the top of stack, and \ ends the program. I'm not sure what the preceding characters do, but nothing that matters in this case.

Try it online!

brainfuck, A000027

Relevant code: ,[.,]

Simple cat program from esolangs.org. Outputs the input.

Try it online!

><>, A000030

Relevant code: # ... ;oi

# mirrors and wraps to the right, which direct it to read io;, which outputs the first character of the input. 0-indexed.

Try it online!

Ruby, A023443

Relevant code: print (0 and gets.to_i-1 ... )

0-indexed. Prints the input minus 1. 0 is truthy in Ruby, but falsey in Python.

Try it online!

Python 3, A000578

Relevant code: print (0 and gets.to_i-1 or int(input())**(2+(1/2>0)));quit()

Ripped off of HyperNeutrino's original post, but it's a pretty well-known polyglot. quit() ends the program.

Try it online!

Python 2, A000290

Relevant code:

print (0 and gets.to_i-1 or int(input())**(2+(1/2>0)));quit()

#coding:utf-8 is required for the Charcoal stuff to work. Also ripped off of HyperNeutrino's original post. quit() ends the program.

Try it online!

Charcoal, A001489

Relevant code: ⎚I±N»

0-indexed. clears the console (Charcoal prints ASCII as-is) and I±N prints the negative of the input. » is a parse error and terminates the program.

Thanks to ASCII-only for help in chat.

Try it online!

Cardinal, A020725

Relevant code:


Adds 1 to the input, and squashes all other pointers.

Try it online!

  • \$\begingroup\$ Looks like exit code for PingPong is the ToS, it wraps at 2^32 as would be expected of a 64-bit signed integer. \$\endgroup\$ Commented Aug 15, 2017 at 1:13
  • \$\begingroup\$ @JonathanAllan cool, thanks. \$\endgroup\$
    – Stephen
    Commented Aug 15, 2017 at 1:15
  • \$\begingroup\$ Do you really need to exit with a parse error if the Charcoal code is already at the end of the program? \$\endgroup\$
    – MD XF
    Commented Aug 17, 2017 at 19:02
  • \$\begingroup\$ @MDXF no, I was (am) planning to add more at the end \$\endgroup\$
    – Stephen
    Commented Aug 17, 2017 at 19:03

5 languages (05AB1E, Actually, CJam, Jelly, MATL), 7 bytes


Try it online!:

  • 05AB1E: sequence A000027 (positive integers: a(n) = n; 1-based)
  • Actually: sequence A023443 (non-negative integers including 1: a(n) = n−1; 0-based)
  • Cjam: sequence A020725 (positive integers excluding 1: a(n) = n+1; 1-based)
  • Jelly: sequence A005843 (non-negative even numbers: a(n) = 2*n; 0-based)
  • MATL: sequence A000290 (squares: a(n) = n2; 1-based). Exits with an error after producing the output.

3 languages: Proton, A000583; Python 3, A000578; Python 2, A000290

Proton, 49 bytes


Try it online!

Python 3, 49 bytes


Try it online!

Python 2, 49 bytes


Try it online!


Proton doesn't have '''...''' strings, so (''',''') becomes ('' ',' ''), which somehow doesn't cause issues. It evaluates to '', making (''',''')!=',' evaluate to True.

Python does have these strings, so (''',''') is just ',' so (''',''')!=',' evaluates to False.

Python 2 uses floor division for integers, so 1/2>0 is false in Python 2 and true in Python 3.

  • \$\begingroup\$ You might be able to add some more langs if you turn the Python line into 1//1;print(int(input())**(2+(1/2>0)+((''',''')!=',')));quit() and then add languages like JavaScript afterwards \$\endgroup\$
    – Stephen
    Commented Aug 15, 2017 at 14:37
  • \$\begingroup\$ @StepHen Sure, that might work, thanks. I'll do that once I get around to adding JavaScript :P \$\endgroup\$
    – hyper-neutrino
    Commented Aug 15, 2017 at 14:43

5 Languages, 107 bytes


Perl: A000035

Using = as a delimiter for s/// means we can easily exclude code we don't want, and using ) as the delimiter for q{} means after printing q in all other languages, we can just work on <> directly, without worrying.


Try it online!

Ruby: A001477

In Ruby, // is actually / (divide by) /.../ (regex match), so as long as the regex is terminated, and converted to a number, we can divide by it safely. __id__ is shorter than .to_s.ord, then we just contain the rest of the code we don't want in 's, set q to gets and print it with all the others.


Try it online!

Python 2: A005843

Using the standard trick to differentiate 2 from 3 and enclosing stuff we don't want in """ and comments.


Try it online!

Python 3: A008585

Try it online!

JavaScript (ES6 browser): A000027

Pretty straightforward for JS, it ended up being easier not to re-use the existing print and go for SpiderMonkey, but that might also be possible too.



6 languages: Cubically 5/6/7/8/9/10, 44 40 32 bytes

Crossed out 44 is still regular 44 ;(


This prints:


DDR'DDR                            get top face sum to 2 (all versions)
       $:                          read input and set notepad to it
         _0                        set notepad to input modulo 2
           ?{...........}          if truthy
             R'DDRDD                reset cube
                    B'              set top face to Cubically version number
                      %0            print top face
                         !{....}   if falsy
                           +00      add 2 to notepad twice
                              %     print

Try it online! (Cubically 6x6x6)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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