25
\$\begingroup\$

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

  • Then-th entry of an OEIS sequence OR
  • The firstn 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 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.
askedAug 14, 2017 at 18:27
SEJPM's user avatar
\$\endgroup\$
3
  • 4
    \$\begingroup\$This post was done in accordance tothis Meta Q&A.\$\endgroup\$CommentedAug 14, 2017 at 18:28
  • \$\begingroup\$Can different languages have different indexing?\$\endgroup\$CommentedAug 14, 2017 at 20:31
  • 2
    \$\begingroup\$@StepHen yes they can.\$\endgroup\$CommentedAug 14, 2017 at 20:32

6 Answers6

17
\$\begingroup\$

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

answeredAug 14, 2017 at 20:22
Mr. Xcoder's user avatar
\$\endgroup\$
4
  • 1
    \$\begingroup\$well you certainly picked the right languages for this one +1 :P\$\endgroup\$CommentedAug 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\$CommentedAug 14, 2017 at 20:36
  • 1
    \$\begingroup\$Remember, this is number of languages, not code-golf :P\$\endgroup\$CommentedAug 14, 2017 at 21:22
  • \$\begingroup\$@StepHen I think 3 is reasonable.\$\endgroup\$CommentedAug 14, 2017 at 21:24
16
\$\begingroup\$

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.

Try it online!

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.

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 readio;, 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-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.

Try it online!

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.

Try it online!

Cardinal,A020725

Relevant code:

 xx%:+.

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

Try it online!

answeredAug 14, 2017 at 19:42
Stephen's user avatar
\$\endgroup\$
4
  • \$\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\$CommentedAug 15, 2017 at 1:13
  • \$\begingroup\$@JonathanAllan cool, thanks.\$\endgroup\$CommentedAug 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\$CommentedAug 17, 2017 at 19:02
  • \$\begingroup\$@MDXF no, I was (am) planning to add more at the end\$\endgroup\$CommentedAug 17, 2017 at 19:03
11
\$\begingroup\$

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.
Erik the Outgolfer's user avatar
Erik the Outgolfer
40.8k5 gold badges46 silver badges125 bronze badges
answeredAug 15, 2017 at 0:15
Luis Mendo's user avatar
\$\endgroup\$
8
\$\begingroup\$

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

answeredAug 14, 2017 at 19:18
hyperneutrino's user avatar
\$\endgroup\$
2
  • \$\begingroup\$You might be able to add some more langs if you turn the Python line into1//1;print(int(input())**(2+(1/2>0)+((''',''')!=',')));quit() and then add languages like JavaScript afterwards\$\endgroup\$CommentedAug 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\$CommentedAug 15, 2017 at 14:43
6
\$\begingroup\$

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)

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, setq togets andprint it with all the others.

s=1/2;1//2..."/.__id__;'...';q=getsprint(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!

Python 3:A008585

Try it online!

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)#`

answeredAug 14, 2017 at 21:14
Dom Hastings's user avatar
\$\endgroup\$
3
\$\begingroup\$

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)

answeredAug 17, 2017 at 19:01
MD XF's user avatar
\$\endgroup\$
0

Your Answer

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

Draft saved
Draft discarded

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.