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 theon-line encyclopedia of integer sequences (OEIS). So what if we made anoff-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 integern.
Output
Your output will either be
- The
n-th entry of an OEIS sequence OR - The first
nentries 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 ofThe versatile integer printerconstant 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) revisionsdo 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 tothis Meta Q&A.\$\endgroup\$SEJPM– SEJPM2017-08-14 18:28:09 +00:00CommentedAug 14, 2017 at 18:28
- \$\begingroup\$Can different languages have different indexing?\$\endgroup\$Stephen– Stephen2017-08-14 20:31:07 +00:00CommentedAug 14, 2017 at 20:31
- 2\$\begingroup\$@StepHen yes they can.\$\endgroup\$SEJPM– SEJPM2017-08-14 20:32:51 +00:00CommentedAug 14, 2017 at 20:32
6 Answers6
3 languages (1 byte) -Pyth (A001477),MATL (A000027),Braingolf (A000217)
Q- Try Pyth online!, 0-indexed (non-negative integers)
- Try MATL online!, 0-indexes (positive integers)
- Try Braingolf online!, 1-indexed (triangular numbers)
How?
Q does the following:
In MATL, it means
+ 1, so it basically evaluates toinput + 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 orBrain-Flak.
- 1\$\begingroup\$well you certainly picked the right languages for this one +1 :P\$\endgroup\$2017-08-14 20:35:21 +00:00CommentedAug 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– Mr. Xcoder2017-08-14 20:36:10 +00:00CommentedAug 14, 2017 at 20:36
- 1\$\begingroup\$Remember, this is number of languages, not code-golf :P\$\endgroup\$Stephen– Stephen2017-08-14 21:22:55 +00:00CommentedAug 14, 2017 at 21:22
- \$\begingroup\$@StepHen I think 3 is reasonable.\$\endgroup\$Mr. Xcoder– Mr. Xcoder2017-08-14 21:24:37 +00:00CommentedAug 14, 2017 at 21:24
10 languages, 122 bytes
#|A=1:0;~@}{\,[.,];oi#coding:utf-8print (0 and gets.to_i-1 or int(input())**(2+(1/2>0)));quit()#⎚I±N»# 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 is1,:0 mean the rest are0, outputs thenth term given inputn. cQuents v0 has a weird bug/feature that when an unexpected but valid token, such as;, is read, it causes parsing to end.
PingPong,A001478
Relevant code:#|A=1:0;~@
Outputs via exit code. 0-indexed.
# skips the next char.= does nothing here.1 pushes1, and: prints1 to STDOUT.0 pushes0.) does nothing.; pushes input,~ pops and pushes-n-1.@ terminates. The exit code is the top of the stack.
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.
brainfuck,A000027
Relevant code:,[.,]
Simple cat program from esolangs.org. Outputs the input.
><>,A000030
Relevant code:# ...;oi
# mirrors and wraps to the right, which direct it to readio;, which outputs the first character of the input. 0-indexed.
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.
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.
Python 2,A000290
Relevant code:
#coding:utf-8print (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.
Charcoal,A001489
Relevant code:⎚I±N»
0-indexed.⎚ clears the console (Charcoal prints ASCII as-is) andI±N prints the negative of the input.» is a parse error and terminates the program.
Thanks to ASCII-only for help in chat.
Cardinal,A020725
Relevant code:
xx%:+.Adds 1 to the input, and squashes all other pointers.
- \$\begingroup\$Looks like exit code for PingPong is the ToS, itwraps at 2^32 as would be expected of a 64-bit signed integer.\$\endgroup\$Jonathan Allan– Jonathan Allan2017-08-15 01:13:07 +00:00CommentedAug 15, 2017 at 1:13
- \$\begingroup\$@JonathanAllan cool, thanks.\$\endgroup\$Stephen– Stephen2017-08-15 01:15:36 +00:00CommentedAug 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– MD XF2017-08-17 19:02:40 +00:00CommentedAug 17, 2017 at 19:02
- \$\begingroup\$@MDXF no, I was (am) planning to add more at the end\$\endgroup\$Stephen– Stephen2017-08-17 19:03:04 +00:00CommentedAug 17, 2017 at 19:03
5 languages (05AB1E,Actually,CJam,Jelly,MATL), 7 bytes
UD>li)+Try it online!:
- 05AB1E: sequenceA000027 (positive integers:a(n) =n; 1-based)
- Actually: sequenceA023443 (non-negative integers including 1:a(n) =n−1; 0-based)
- Cjam: sequenceA020725 (positive integers excluding 1:a(n) =n+1; 1-based)
- Jelly: sequenceA005843 (non-negative even numbers:a(n) = 2*n; 0-based)
- MATL: sequenceA000290 (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)+((''',''')!=',')))Python 3, 49 bytes
print(int(input())**(2+(1/2>0)+((''',''')!=',')))Python 2, 49 bytes
print(int(input())**(2+(1/2>0)+((''',''')!=',')))Explanation
Proton doesn't have'''...''' strings, so(''',''') becomes('' ',' ''), which somehow doesn't cause issues. It evaluates to'', making(''',''')!=',' evaluate toTrue.
Python does have these strings, so(''',''') is just',' so(''',''')!=',' evaluates toFalse.
Python 2 uses floor division for integers, so1/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– Stephen2017-08-15 14:37:09 +00:00CommentedAug 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\$2017-08-15 14:43:47 +00:00CommentedAug 15, 2017 at 14:43
5 Languages, 107 bytes
s=1/2;1//2;q=int(input())*([2,3][s>0]);"""/.__id__;'alert(+prompt()+1);`"""#=;#';q=getsprint(q)#)|<>%2)#`Perl:A000035
Using= as a delimiter fors/// means we can easily exclude code we don't want, and using) as the delimiter forq{} means afterprintingq in all other languages, we can just work on<> directly, without worrying.
s/1...q/i...#/;print(<>%2)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, setq togets andprint it with all the others.
s=1/2;1//2..."/.__id__;'...';q=getsprint(q)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)Python 3:A008585
JavaScript (ES6 browser):A000027
Pretty straightforward for JS, it ended up being easier not to re-use the existingprint 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=getsprint(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:
- A010710 in Cubically 5x5x5
- A010711 in Cubically 6x6x6
- A010712 in Cubically 7x7x7
- A010713 in Cubically 8x8x8
- A010714 in Cubically 9x9x9
- A010715 in Cubically 10x10x10
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 % printTry it online! (Cubically 6x6x6)
Explore related questions
See similar questions with these tags.







