# Polyglot the (non constant) OEIS!

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.

## Introduction

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!

## Input

Your input will be a non-negative integer n.

## Output

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.
• This post was done in accordance to this Meta Q&A. – SEJPM Aug 14 '17 at 18:28
• Can different languages have different indexing? – Stephen Aug 14 '17 at 20:31
• @StepHen yes they can. – SEJPM Aug 14 '17 at 20:32

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

Q


# How?

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.

## Mini-polyglot

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

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

# 10 languages, 122 bytes

#|A=1:0;~@}{\,[.,];oi
#coding:utf-8
print (0 and gets.to_i-1 or int(input())**(2+(1/2>0)));quit()#⎚Ｉ±Ｎ»
# x
#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:

#coding:utf-8
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: ⎚Ｉ±Ｎ»

0-indexed. ⎚ clears the console (Charcoal prints ASCII as-is) and Ｉ±Ｎ 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:

 x
x%:+.


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

Try it online!

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

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

UD>li)+


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

print(int(input())**(2+(1/2>0)+((''',''')!=',')))


Try it online!

## Python 3, 49 bytes

print(int(input())**(2+(1/2>0)+((''',''')!=',')))


Try it online!

## Python 2, 49 bytes

print(int(input())**(2+(1/2>0)+((''',''')!=',')))


Try it online!

# Explanation

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.

• 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 – Stephen Aug 15 '17 at 14:37
• @StepHen Sure, that might work, thanks. I'll do that once I get around to adding JavaScript :P – HyperNeutrino Aug 15 '17 at 14:43

## 5 Languages, 107 bytes

s=1/2;1//2;q=int(input())*([2,3][s>0]);"""/.__id__;'
alert(+prompt()+1);"""#=;#';q=gets
print(q)#)|<>%2)#


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

s/1...q/i...#/;
print(<>%2)


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.

s=1/2;1//2..."/.__id__;'...';q=gets
print(q)


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.

s=1/2;1//2;q=int(input())*([2,3][s>0]);"""/..."""
print(q)


Try it online!

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.

s=1/2;1//2;q=int(input())*([2,3][s>0]);"""/.__id__;'
alert(+prompt()+1);"""#=;#';q=gets
print(q)#)|<>%2)#

# 6 languages: Cubically 5/6/7/8/9/10, 4440 32 bytes

Crossed out 44 is still regular 44 ;(

DDR'DDR$:_0?{R'DDRDDB'%0}!{+00%}  This prints: Explanation: DDR'DDR$:_0?{R'DDRDDB'%0}!{+00%}
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)