Polyglot the OEIS!

41

2

Note: This challenge has been moved to Polyglot the (non constant) OEIS! to avoid closure.

Introduction

We all know and love the on-line encyclopedia of integer sequences (OEIS). So what if we made an off-line version? 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.

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.

SEJPM

Posted 2017-08-06T18:11:49.887

Reputation: 3 203

Question was closed 2017-08-14T10:32:59.147

The fact that it's mots sequence/language pairs seems kind of weird. – Okx – 2017-08-06T18:55:36.220

Do different versions/implementations of the same language count as different langauges (like Python2 and Python3, or like browser JS and Node.js)? – None – 2017-08-06T21:35:00.150

@ThePirateBay different versions do count as different languages (see point 4 of "Any final Words / Rules?"). As for the implementations, I can't find any prior ruling on this particular question. However as they practically define different languages, you can count them as different (but have to specify the interpreter as well). This also makes sense here because you'd have to squeeze different sequences out of the implementations ;) – SEJPM – 2017-08-07T00:07:27.083

3@ppperry I have to disagree: While every entry from there will be a valid entry here, the reverse is not true. Here all entries have much more freedom and can use non-trivial sequences. Examples I have seen in the two most competetitives answers include the even numbers, the prime numbers, the squares, the non-negative integers and the cubic numbers. – SEJPM – 2017-08-07T15:53:54.557

For the uninitiated reader: This question was closed as a duplicate because entries from "the versatile integer printer" are valid and (highly) competitive here as well and because newer challenges generally get closed in favor of old ones. – SEJPM – 2017-08-08T12:28:47.780

I really don't think this is a dupe, especially because of the difference in scoring. – Stephen – 2017-08-08T16:07:11.303

I don't think this is a dupe. People (including me) choose to wimp out and use constant sequences. It's not supposed to be that way and it doesn't have to. Answers from there are sometimes valid here, yes, but answers here are not necessarily valid there. This is nothing like the [tag:polyglot] [tag:answer-chaining] challenge, but I could take that polyglot and win this challenge. – MD XF – 2017-08-08T16:09:53.453

4Look at the (currently) winning answer; it uses almost all constant sequences. – pppery – 2017-08-08T19:16:24.257

1Meta discussion about dupe – programmer5000 – 2017-08-13T02:27:22.743

3

The version of this challenge with constant sequences banned lives here now.

– SEJPM – 2017-08-14T18:29:00.840

Answers

38

26 languages: C, C++, Cubically, rk, what, Bash, Morse, Ook!, str, Charcoal, Commercial, S.I.L.O.S, memescript, Forked, TRANSCRIPT, Braingolf, Fission, Arcyou, Beam, Beatnik, Cood, COW, Emoji, ><>, Set, NTFJ

Over 1000 bytes >.< but I'm gonna go for the most languages.

Hit Page Down about 10 times if you don't want a description of all the languages.

#\
//ha kkkkkkkkkk ja ha kkkkkkkkkkd ja skd  I7Oq2_
#include<stdio.h>//$+77%6& ..... rk:start print: "11" rk:end  ?!!!!!!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!??!????!        Ook. Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. ⎚8» ##########################################
 /*
echo -n 3;exit
Hey, waiter!
I want 25 of this.
How much is it?
The bill, please.
foo now 9 dollars off!
foo has been selling out worldwide!
a = 10
printInt a
filler what the frick frack thumbtack diddily dack crack pack quarterback frick frack (p 22)
>F9+%&'L+:+:H
Ju is here.
>Ju, 32
>X Ju
 set ! 50
 set ! 56
oom MoO OOM  26➡ #####/
*/main(int a){getchar();printf("%d",sizeof(' '));}/* R"21"
 >2n7n; */

This outputs:

(Links are not all current, I'll eventually update them. I have verified each language.)

C/C++

sizeof(' ') is 1 in C++ and 4 in C. Here's the C/C++ code:

#include <stdio.h>
main(){getchar();printf("%d",sizeof(' '));}
  • #include <stdio.h> is needed for C++. (This is why I don't like it.)
  • getchar(); is there because we still technically need input.
  • printf("%d",sizeof(' ') prints 4 in C and 1 in C++.

Update - the echo -n 3;exit is ignored via \ at the end of the comment on line 1.

Cubically

Cubically ignores everything it doesn't care about as long as no functions get called.

$+7+7%6&
$          read int as input
 +7+7      double it (could be +77, I'll golf everything more if it comes to that)
     %6    print output
       &   exit (the `main()` would cause an infinite loop)

rk

rk is horrible, but good for polyglotting. It ignores everything before rk:start and after rk:end:

rk:start print: "11" rk:end

Pretty simple. A010850 is a constant sequence. "Input is taken via command line arguments." :P

what

The what interpreter reads three bytes at a time. Very stupid but useful.

?!!!??(x50)??!

Gets input (uselessly), goes to next memory cell, adds the ASCII value for 2 (50) to the current memory cell and outputs.

Bash

# <comment>
echo -n 3; exit
<everything ignored because parser already exited>

Also takes input via "command line arguments". I love constant sequences.

Morse

Morse Code is the oldest language used in this thread, I can guarantee. ;) This uses an interpreter I wrote last year for fun. It conveniently ignores everything it doesn't care about.

.....

Constant sequences probably weren't what the OP had in mind when creating the challenge...

Ook!

Ook! is a Trivial Brainf**k Substitution. The interpreter I found is really crappy, reads 11 characters at a time and checks if it's something it cares about. Pasting the code at the end of the first line magically lined it up properly, so the interpreter noticed the Ook! code.

Ook. Ook! Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook! Ook. 

This is equivalent to Brainf**k's ,>+(x48).. Read a character, move to next memory cell, increment to 48 (ASCII code for 0) and print.

str

The str code wanted to be right at the top because something around #include <stdio.h> made it bug out. I had to rearrange the what and Ook! code, since I added something before both of them.

# // I7Oq

# is apparently a valid preprocessing token in C/C++. // comments it out. (That's a capital letter o, in case your screen tries to deceive you.)

  • I - read input
  • 7 - push 7
  • O - output
  • q - turn off STDOUT just in case

I think it's real clever how I is for input and O is for output. Nice language, Conor!

Charcoal

Wow, I like this language, I'm gonna use it more sometime.

Luckily, there's a command to clear the output buffer, . So it just echoes everything up to the on line 2, then clears that. The Charcoal code we care about looks like this:

⎚8»

8 prints 8. » exits with a parse error, which is allowed by default.

Commercial

This one was a bit less nice because it wanted me to have its code on separate lines. I had to rearrange the C/C++ comments a bit.

For some reason, C emitted a warning and then didn't compile when I replaced the // with /*. So it's on its own line, making Bash annoyed but still prints the desired number.

foo now 9 dollars off!
foo has been selling out worldwide!
  • variable now x dollars off creates a new variable variable with value x.
  • variable has been selling out worldwide! prints the variable's value.

At least the interpreter is forgiving about unrecognized code...

Oh, I also updated all the TIO links. That was a pain so I'll probably only do so every 10 or when I quit working on this polyglot. Fun challenge, thanks!

S.I.L.O.S

That had one of the clearest, most concise READMEs I've ever seen. Simple as this:

a = 10
printInt 10

Adding this code didn't even break anything!

Memescript 1.0

Why does this language exist >.<

The interpreter was being lame so I had to add filler to get it to see what the.

filler what the frick frack thumbtack diddily dack crack pack quarterback frick frack
  • what the - start code
  • frick frack thumbtack - push 11
  • diddily dack crack pack - add 5
  • quarterback frick frack - output as integer

Forked

Forked is my new 2d lang, it's only partially implemented. It's not in a triangle or a cube or anything interesting, it's just a fun simple esolang.

Unfortunately, having # // I70q on the first line had a mirror / in the way of the source code. I moved some things around so the mirrors look like this:

 \
//

The mirrors are pretty self-explanatory; the code enters from the top left and exits at the bottom left. Then it hits this code near the bottom:

>F9+%&

> directs the IP west. F pushes 15, 9 pushes 9. + adds them, % prints as integer, & exits.

Note: This may not work in future Forked versions, depending on how # will handle invalidity.

TRANSCRIPT

This is a cool language. I don't really understand some of the syntax (specifically, >), but it's fun nevertheless. Also forgiving about syntax errors which is why I chose to use it.

Here's the code we care about:

Ju is here.
>Ju, 32
>X Ju
  • Ju is here. defines an NPC (variable) named Ju. (Short for Julie, which was used in the example.)
  • >Ju, 32 puts 32 in Ju's memory (sets it to 32).
  • >X Ju prints Ju. (Where did X come from?!?)

Braingolf

Apparently, the code does some wacked out stuff to the stack but outputs 0 at EOF, so I found a place I could put the code without breaking anything else, found a sequence that ended in 0, and let it do its implicit output at the end.

2_

Pushes 2 and prints it. 0 is printed at the end, printing 20. More constant sequences, yay!

Fission

For such a complicated language, this was pretty easy - just modified this:

R"21"

Prints 21. Surprisingly, putting this anywhere in the code worked just fine.

  • R creates atom travelling right.
  • "21" stores the string 21 in that atom.
  • Implicit output at the end of the program, I guess.

Arcyou

Another language forgiving about syntax errors. Here's the code we care about:

(p 22)

Arcyou is pretty much identical to LISP, but golfier. p is print, 22 is 22.

Also, it printed None due to the main(). I added a there, C++ complained, I made it int a and everything's running smoothly again.

Beam

The hardest part about adding this language was finding the spec. Luckily, there's a mirror of esolangs.org! Thanks, totallyhuman!

Beam uses the same control flow as Forked but that's it. So I put its code after Forked's exit command.

'L+:+:H

' increments the store and L sets the beam to the store. + increments, : outputs as integer.

I tried ++:+:H first, but the beam apparently is not initialized to 0. The store is, though.

Beatnik

Beatnik is a language almost as awful as some I've written and am planning to write. It uses Scrabble word values. Here's its code:

ha kkkkkkkkkk ja ha kkkkkkkkkkd ja skd

Here is the Scrabble values for those:

5 50 9 5 52 9 17
  • 5 50 - push 50
  • 9 - print as ASCII
  • 5 52 - push 52
  • 9 - print as ASCII
  • 17 - exit

I used a comma and a bunch of Z's initially, which messed with str. Fixed by removing the useless comma and changing 5 z's to 10 k's.

Cood

Cood cares about this (explanation on the right)

Hey, waiter!           (start program)
I want 25 of this.     (set memory to 25)
How much is it?        (print as int)
The bill, please.      (finish script)

COW

Yay, a non-constant sequence! :D

oom MoO OOM
oom          read integer
    MoO      increment
        OOM  print as integer

Emoji

26➡
..   push string
 26    "26"
    ➡  print top of stack

><>

Another language I'm going to use more; I love how this wraps.

It initially hits #, which bounces the IP backwards, wraps around, hits \, which wraps vertically to the bottom, hits >, then it sees 2n7n;.

2n7n;
2      push 2
 n     output
  7    push 7
   n   output
    ;  exit

Set

I recall this being used in the . Luckily, ASCII-only's TIO interpreter doesn't care about syntax errors!\

set ! 50         (print 2)
set ! 56         (print 8)

NTFJ

That's another one of your langs I've used, Conor.... this is possibly the strangest. All I do is push truthy values (#) and use / to push the number of items on the stack to the stack and * to print.

(line 3) ##########################################
(line 4) /*
(line 21) #####/
(line 22) *

I didn't really mess with the code in the middle. It probably does things to the stack, and this will probably be a pain down the road, but whatever, it works.

MD XF

Posted 2017-08-06T18:11:49.887

Reputation: 11 605

sizeof(' ') is 4 in C but 1 in C++ – o11c – 2017-08-07T03:22:18.763

hey :( charcoal is as good as rk for polyglotting (using clear and double right angle bracket to start/end) – ASCII-only – 2017-08-08T01:23:56.160

@ASCII-only I'll look into adding it when I'm back on a PC – MD XF – 2017-08-08T01:27:13.020

@ASCII-only how do I make Charcoal not just echo everything? – MD XF – 2017-08-08T02:35:11.177

you can clear it? also end it with a parse error via », see the codepage in the wiki for ascii codes for use with -e – ASCII-only – 2017-08-08T02:37:52.660

hey :( why not just ⎚8» (plus you shouldn't use charcoal for such an easy task :P it's a golflang after all) – ASCII-only – 2017-08-08T06:50:18.990

You've got two constant 11s... – boboquack – 2017-08-08T08:12:53.767

@boboquack uh, not sure why that happened. Fixed. – MD XF – 2017-08-08T15:42:28.793

@ASCII-only oh, that's pretty simple lol. Thanks, edited. – MD XF – 2017-08-08T15:51:05.343

technically printf("%d",sizeof(' ')) is undefined behavior, because size_t should be printed with %zu – phuclv – 2017-08-09T03:23:00.533

Haha, fission code does something funny. \ in R"21"\ is mirror and sends atom somewhere in your code, where it meets smth that make it print internal info :D (there is no implicit output in fission) – Dead Possum – 2017-08-09T08:41:16.740

1And you have line >F9+%&'L+:+:H, which messes up fission, cos L spawns atom. Output: 21uui k }} k 21 – Dead Possum – 2017-08-09T08:50:57.137

1This answer is REALLY good : lots of langages, and a clear link and explanation for each of them. And the sequence is in order. You deserve more upvotes! – Olivier Dulac – 2017-08-09T12:08:03.493

@DeadPossum Oh, I never noticed... seems KSmarts has found a fix, I'll test it out. – MD XF – 2017-08-09T15:54:43.237

@KSmarts Didn't fix it, but I found something that did. – MD XF – 2017-08-09T16:07:23.063

28

9 Languages, 217 bytes

2/3#^4 9 


5   
if 1:
  x="+++++++[>+++++++<-]>."#3
  R = input()
  try:
    print(int(eval(chr(49)+chr(47)+chr(40)+chr(49)+chr(47)+chr(50)+chr(41))*int(R)))
  except:
    print(7**int(R))
    R="6"#N;
    n=2
  R

Jelly outputs the first n elements of the sequence instead of the n-th element.

><> and Whitespace exit with an error after giving the correct output, which is allowed by default.

How it works

Jelly

Jelly sees only the R at the bottom, which tells it to output range(input).

Python 2

After removing unused lines, Python 2 sees:

if 1:                     # just do it, where it is the following:
  R = input()             # set input to R
  try:                    # try:
    print(int(eval(chr(49)+chr(47)+chr(40)+chr(49)+chr(47)+chr(50)+chr(41))*int(R))
  # print(int(1/(1/2))*int(R)). Floor division causes 1/(1/2) to be
  # 1/0, raising a division by 0 error, going into the except block
  except:
    print(7**int(R))      # print 7 to the power of R.

Python 3

if 1:                     # just do it, where it is the following:
  R = input()             # set input to R
  try:                    # try:
    print(int(eval(chr(49)+chr(47)+chr(40)+chr(49)+chr(47)+chr(50)+chr(41))*int(R))
  # print(int(1/(1/2))*int(R)). Float division causes 1/(1/2) to be
  # 1/0.5=2. This is multiplies by R and printed.
  except: # The except block is not called
    print(7**int(R))

Brainfuck

Brainfuck sees:

+++++++    Set counter cell to 7
[          While counter != 0
  >          Go to storage cell (default to 0)
  +++++++    Increase by 7
  <          Return to counter cell
  -          Decrement
]          EndWhile
>.         Print out chr value of storage cell => chr(49) = "1"

///

/// sees:

<Something including the top-left 2>
# replace the empty string with 2 and output

Ohm

Ohm sees:

<Something including the top 9>
# implicitly output 9.

><>

><> sees:

2/3#^4 9   -- the IP travels right (pushing 2) until it hits `/`
 f         -- it travels up (pushing f=15) until it hits `/`
           -- it travels right (pushing 3) until it hits `#`
           -- it travels left (pushing 3) until it hits `/`
           -- it travels down (pushing f=15) until it hits `/`
           -- it travels left (pushing 2 then 9 then 4) until it hits `^`
           -- it travels up. When it hits `n`, it prints the 4
           -- it then hits some characters ><> doesn't like,
           -- ending the program with an error.
    n

Fission

Fission sees:

R="6"#N;
R          - start an IP/atom going right
  "        - start string
   6       - 6
    "      - end string
      N    - add newline
       ;   - end program. (implicit) print

(it sees other lines, but those don't affect output) Whitespace

Some of this has likely been lost in copy-paste.

Whitespace sees the following, where N represents linefeed, S represents space, and T represents tab. All actual newlines should be ignored.

NSSN
SSSN  -- push 0
TN    -- print it
NTNSNSSNSSSSNSSNSSSSNSSNSSSSNSSSSNSSSSNSSN

fireflame241

Posted 2017-08-06T18:11:49.887

Reputation: 7 021

22

9 Languages, 107 98 bytes

Sub 100!

Python 2, Python 3, JavaScript, PHP, brainfuck, Retina, Gaia, ><>, Ohm.

2 //1;""""0
;function a($n){return $n**(2+!"0");};
/*."""
print(input()*2)
1#/i$%o<
() #\7751cep*/

A005843 in Python 2

A020338 in Python 3

A000290 in JavaScript

A000578 in PHP (run with -r)

A000012 in brainfuck (IO by byte value)

A001477 in Retina

A000040 in Gaia

A000035 in ><> (IO by byte value)

A000004 in Ohm

Explanations

Python 2 and 3

All the two Python versions see is the following:

print(input()*2)

The difference in their behaviour is that input() evals the line of input read in Python 2, but just returns the string in Python 3. So Python 2 prints 2n, but Python 3 prints the string of n repeated twice.

JavaScript and PHP

What these languages see is the following:

2
;function a($n){return $n**(2+!"0");};

Which defines a function a that computes the result. The difference in behaviour comes from !"0".

In JavaScript, "0" is a truthy value. So !"0" becomes false, which gets cast to 0. Thus JavaScript computes $n to the power 2+0.

In PHP, the "0" is actually a falsy value, because (for whatever reason) it gets cast to the number 0 before being treated as a boolean. So !"0" is true. Thus PHP computes $n to the power 2+1.

brainfuck

The + in the JS/PHP part increments the cell, then the . in the middle outputs it. Thus it outputs the byte value 1 for any input.

Retina

Retina does a lot of regex substitutions on the input, using regexes that don't even remotely match any number that would be given as input (so no replacements are made). Then it prints the result of the replacements, which is just the input.

Gaia

The only line executed by Gaia is:

() #\7751cep*/

(               Decrement the input
 ) #            Find the first (input-1) numbers such that (number+1) is true
    \           Delete that list of numbers
     7751c      Push the string "ṇ"
          e     Eval it (the command for "nth prime number")
           p    Print the result
            */  Some other stuff that doesn't matter

><>

What's relevant to ><> is

2 /




  /i$%o<

The fish starts at the top left, pushing 2. It moves over to the /, mirroring and looping to the bottom of the code. It hits the other / and move right. It pushes input (i), swaps the top stack elements ($), computes input mod 2 (%), and outputs as a byte (o). Then it moves left and tries to output again, which causes the program to exit with an error since there's nothing left on the stack.

Ohm

Ohm only executes the first line:

2 //1;""""0

Which is some random stuff and then 0. Only the top stack element is printed implicitly.

Business Cat

Posted 2017-08-06T18:11:49.887

Reputation: 8 927

for whatever reason The reason probably lies in the fact that all input to PHP comes as strings ($argn, $argv, $_GET, $_POST, DB results) combined with the loose typing (PHP has types, but it knows no type declarations - apart from objects and functions). PHP must be able to calculate with strings or you´d have to cast everything you need as a number explicitly; and that would be a tremendously enerving business. – Titus – 2017-08-07T23:19:03.903

12

5 languages - Braingolf, Pyth / GolfScript / Brain-Flak / Pyke / Brachylog, MATL, Retina / Jelly / Commentator and 05AB1E / 2sable / Oasis

Q

This has two three multi-language-sequence polyglots. In Braingolf, this computes the triangular numbers (A000217), Pyth and GolfScript and Pyke (and Brain-Flak) are 0-indexed and use the non-negative integers (A001477), MATL is 0-indexed and uses the positive integers (A000027), Retina, Commentator and Jelly always output 0 (A000004), regardless of the input and 05AB1E, Oasis and 2sable always output 1 (A000012).


How?

In Braingolf, the nth triangular number is calculated using Q (1-indexed).

In Pyth and GolfScipt and Pyke (and Brain-Flak), the input just gets printed as it is.

In MATL, Q means increment by 1, hence it displays the number given as input plus 1.

In Retina, Commentator and Jelly, Q always prints 0. Similarly, 05AB1E, Oasis and 2sable output 1.

Mr. Xcoder

Posted 2017-08-06T18:11:49.887

Reputation: 39 774

Trying to find a work-around with Golfscript too – Mr. Xcoder – 2017-08-07T08:31:02.417

And A000004 in Retina. – jimmy23013 – 2017-08-08T18:31:54.667

@jimmy23013 Yay, thanks a lot! – Mr. Xcoder – 2017-08-08T20:07:14.373

1This has gone crazy.... – Mr. Xcoder – 2017-08-08T21:11:56.163

1

Brachylog can join Pyth, GolfScript, and Brain-Flak. Try it here.

– DanTheMan – 2017-08-09T04:47:18.480

Also, it's too bad there's no all 81s sequence, as that would work in HQ9+ with byte value output. – DanTheMan – 2017-08-09T04:57:48.770

1@DanTheMan Thanks for Brachylog. – Mr. Xcoder – 2017-08-09T13:42:09.383

8

5 languages (05AB1E, CJam, Jelly, MATL, Retina), 8 bytes

rdK*p
%2

This produces:

The CJam program exits with an error after producing the correct result in STDOUT, which is allowed by default.

Luis Mendo

Posted 2017-08-06T18:11:49.887

Reputation: 87 464

6

3 languages, QBIC, QBasic and Javascript

'';/*`
input a
?a*q
''*/f=()=>1;

QBasic, all 0's; A000004

'';/*`          the ' makes this a comment for QBasic
input a         this asks for an input, stores it in a
?a*q            Multiplies a by q, which is not set in QBasic and therefore 0. ? prints this.
''*/f=()=>1;    And another comment

QBIC, positive ints, A000027

'';/*`          The ' opens a code literal: This tells the QBIC interpreter that the next bit is pure QBasic. 
                The following ' injects a comment in the output QBasic code, the ` at the end closes the code literal.
input a         this does the same as the QBasic bit
?a*q            Multiplies a by q, which is 1 in QBIC and just yields the input. ? prints this.
''*/f=()=>1;    And another comment

Javascript, all 1's, A000012

'';/*`          ''; is mostly harmless. /* opens a multiline comment. ` is ignored
input a         commented
?a*q            and commented
''*/f=()=>1;    This closes the comment and defines function f() that always just returns 1

steenbergh

Posted 2017-08-06T18:11:49.887

Reputation: 7 772

4

3 languages: Gaia, CJam, Retina, 7 bytes

1_0

@+

A005843 in Gaia, A010850 in CJam, and A000004 in Retina.

Try it Gaia!

Try it CJam!

Try it Retina!

Explanations

Gaia

Gaia only executes the bottom line, which reads input (@) and adds it to itself.

CJam

1      Push 1
 _     Copy it
  0    Push 0
   @   Bring the bottom 1 to the top
    +  Add 1+0, making the stack `[1 1]`. Implicity push the stack flatten and joined.

Retina

Replaces instances of 1_0 in the input with nothing. Then counts and outputs the matches of the regex @+ in the result. Since this won't ever appear, it outputs 0 for any n.

Business Cat

Posted 2017-08-06T18:11:49.887

Reputation: 8 927

3

11 languages: C, C++, JavaScript (nodejs), Ruby, JavaScript (modern browser), Perl, dc, ><>, brainfuck, JavaScript (spidermonkey), and Pyramid Scheme, 342 bytes

I wanted to see if I could break 9 10. I decided to use mainly non-esoteric languages.

        //;<<E;#6nq>>>-[++>+[+<]>]>^\
/*   ;n7<>>                       / \:
#include <stdio.h>              //out\
//                              ^-----
//                              -
struct k {};int main(){printf("%i",1+sizeof(struct k));}
//;\ 
E
//;\
`echo`;  print($??3:5)
;//;#*/  console['log'](this['window']?4:this['print']?9:10)

Results I was able to verify (for input 4) on my machine:

Result in "C" (A000004):
> gcc normal.c -o normal && normal.exe 4
1
Result in "C++" (A000012):
> g++ normal.cpp -o normal && normal.exe 4
2
Result in "JavaScript" (A007395):
> node normal.js 4
10
Result in "Ruby" (A010701):
> ruby normal.rb 4
3
Result in "Perl" (A010716):
> perl -f normal.pl 4
5
Result in "dc" (A010722):
> echo 4 | dc -f normal.dc
6

Pyramid Scheme

Conor O'Brien

Posted 2017-08-06T18:11:49.887

Reputation: 36 228

2

2 languages: /// and ><>

/9/0//8/0//7/0//6/0//5/0//4/0//3/0//2/0//1/0//00/0//
>1n;//

/// outputs https://oeis.org/A000004 all 0's, and ><> does https://oeis.org/A000012 all 1's

Try ><> online!

Try /// online!

steenbergh

Posted 2017-08-06T18:11:49.887

Reputation: 7 772

Is there info on /// somewhere? The link on TIO points to https://esolangs.org/wiki//// which obviously doesn't work

– LangeHaare – 2017-08-07T08:23:23.153

@LangeHaare Search esolangs for "Slashes" – KSmarts – 2017-08-07T13:33:18.753

2@LangeHaare that would work, but esolangs.org is down. – Stephen – 2017-08-08T20:24:30.557

@StepHen You can use esolangs.zem.fi, it's a mirror of esolangs.org and it's working :) – MD XF – 2017-08-08T21:22:45.370

@MDXF yes, but http://esolangs.zem.fi/wiki/// doesn't – Stephen – 2017-08-08T21:31:10.060

@StepHen esolangs.zem.fi/wiki/Slashes – MD XF – 2017-08-08T21:40:59.387

2@LangeHaare esolang is back up, the link to /// should work now. – steenbergh – 2017-08-09T05:35:02.240

2

30 languageversions, 4 bytes

B3%0

This works with 30 different versions (cube sizes) of Cubically.

I promise I'm not cheating!

However, I'd appreciate it if this answer didn't get accepted. There are other more impressive polyglots, including my other (previously winning) one.

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.

This works in 30 different cube sizes a.k.a. versions of Cubically. I added support for multiple cube sizes last night and made changes live this morning. Each cube size is considered a different language version due to the fact that each cube size completely changes how math is done in the language.

I realized afterwards that this feature is very useful for polyglotting. As making the change was very difficult, useful for lots of things, and required hours of messing with dynamic memory in C, I clearly did not add it just for that reason.

Explanation

B3 turns the BACK face 90° clockwise three times. In Cubically 3x3x3, faces have nine cubelets (three per line), so this gets the cube to look like this:

   111
   000
   000
511222330444
511222330444
511222330444
   555
   555
   333

That's useful, because in Cubically 4x4x4, it looks like this:

    1111
    0000
    0000
    0000
5111222233304444
5111222233304444
5111222233304444
5111222233304444
    5555
    5555
    5555
    3333

Run-down

Version   Sequence
2x2x2     A007395
3x3x3     A010701
4x4x4     A010709
5x5x5     A010716
6x6x6     A010722
7x7x7     A010727
8x8x8     A010731
9x9x9     A010734
10x10x10  A010692
...       ...
32x32x32  A010871

Looks like the constant sequences finally stopped at 32. Seems random but there you are.

MD XF

Posted 2017-08-06T18:11:49.887

Reputation: 11 605

This would win the versitaile integer printer challenge! – pppery – 2017-08-10T22:09:07.417

@ppperry That's true, because this basically prints its version number. With enough memory, this could print an unlimited number of integers. – MD XF – 2017-08-10T22:10:15.340

1

4 languages, Braingolf, 2col, arcplus, Lean Mean Bean Machine

 O
 2
+$
_/
1_
; 
(p
4)
3 

That's right! I've successfully created a polyglot of all of my own languages!

Braingolf, A000012, the all 1s sequence.

Try it online!

Braingolf usually has implicit output of the top of the stack at program termination, but the semicolon prevents that. As a result, the only important code is this:

1_
; 

1_ pushes 1, then pops and prints the top of the stack, while ; suppresses implicit output. There are no other braingolf print operators in the code, so nothing else is printed.

However it's a little more difficult than that, as polyglots tend to be. The $ on line 3 is LMBM's "print value" operator, but is Braingolf's "silent" operator. This means that normally the $ would "silence" the _ in Braingolf, and cause it to silently pop the top of the stack. As a result we throw in an extra line:

_/

The slash is explained under LMBM, but the underscore is for Braingolf, it pops the top of the stack before we push the 1, consuming the silent operator in the process. This allows our 1_ to function as expected.

2col, A010701, the all 3s sequence.

Try it in 2collIDE!

2col is to blame for the peculiar layout of the code, as 2col requires every line to be no more than 2 characters in width. Some of these lines do some weird stuff in 2col, but ultimately as there is no valid 2col print operator in this code, the implicit output kicks in and outputs the return value of the last line.

3

This is the last line, an integer literal, which returns itself.

2col is also the cause of the + on line 3. This does nothing, but prevents 2col throwing a TypeError when trying to execute the $ command.

arcplus, A010709, the all 4s sequence.

Try it online! (code not included)

arcplus is inspired by arcyou, which is inspired by LISP. arcplus ignores everything not in parentheses. Here's the bit in parentheses:

(p
4)

This is a function call. Specifically the p function, which is shorthand for print. Any whitespace is valid separator between the function name and the argument, including a newline, so this is essentially (print 4). I hope I don't need to explain what that does.

Lean Mean Bean Machine, A007395, the all 2s sequence.

No online interpreter available

This one was surprisingly easy, despite being a rather awkward 2d language. Here's what matters for LMBM:

 O
 2
+$
_/
1_
; 

O is a spawn point. A marble is spawned here with a spin of 1, and a value of 0. It hits the 2, setting its value to 2, then hits the $, printing its value. The / moves the marble one space to the left, and changes its spin to 0, note that the underscore to the left of the slash is not executed, as "gravity" takes effect after the left shift before the marble has time to execute another symbol. The marble then drops to 1, setting its value to 1, and finally hits the semicolon, silently killing the marble. LMBM terminates once all marbles are destroyed.

Skidsdev

Posted 2017-08-06T18:11:49.887

Reputation: 9 656

0

C89, C99, C++, Bash, Python

Look, ma, no esolangs!

#include<stdio.h>/*
"""
"; */int x=32//*
/4+//* */
4;/*
echo 3;exit
"""
#*/
#define print(y)main(){printf("%d",x-(int)sizeof(' '));}
print(2)

This prints:

C89

Single-line comments did not exist in C89, so it sees this:

#include<stdio.h>

     int x=32/

4;



#define print(y)main(){printf("%d",x-(int)sizeof(' '));}

So x is 8, sizeof(' ') is 4, outputs 4.

C99

Single-line comments did exist in C99, so it sees this:

#include <stdio.h>

     int x=32
/4+
4;



#define print(y)main(){printf("%d",x-(int)sizeof(' '));}

So x is set to 12, sizeof(' ') is 4, output is 8.

C++

C++ sees the same thing as C99 but sizeof(' ') is 1. Outputs 11.

Bash

Bash sees this:

"""
"; */int x=32//*
/4+//* */
4;/*
echo 3;exit

Okay, so those first four lines cause a lot of parsing errors. Other than that, prints 3.

Python

Python sees this:

print(2)

Everything else is commented out one way or another. Prints 2.

MD XF

Posted 2017-08-06T18:11:49.887

Reputation: 11 605