Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is an challenge in which each answer builds on the previous answer. I recommend sorting the thread by "oldest" in order to be sure about the order in which the posts are made.

The task

The nth program to be submitted must run in n different languages; specifically, all the languages added in previous programs to be submitted, plus one more. The program must output 1 when run in the first language used in answers to this question, 2 when run in the second language, and so on. For example, the first answer could print 1 when run in Python 3, and the second answer could output 1 when run in Python 3 and 2 when run in JavaScript; in this case, the third answer would have to output 1 when run in Python 3, 2 when run in JavaScript, and 3 when run in some other language.

Additional rules

  • Your program must run without erroring out or crashing. Warnings (and other stderr output) are acceptable, but the program must exit normally (e.g. by running off the end of the program, or via a command such as exit that performs normal program termination).
  • Each answer must be no more than 20% or 20 bytes (whichever is larger) longer than the previous answer. (This is to prevent the use of languages like Lenguage spamming up the thread, and to encourage at least a minor amount of golfing.)
  • Using different versions of the same language is allowed (although obviously they'll have to print different numbers, so you'll need to fit a version check into the polyglot). However, you may not use a language feature that returns the language's version number. Repeating the exact same language is, obviously, impossible (as the program would have to deterministically print one of two different numbers).
  • Tricks like excessive comment abuse, despite being banned in some polyglot competitions, are just fine here.
  • You don't have to use the previous answers as a guide to writing your own (you can rewrite the whole program if you like, as long as it complies with the spec); however, basing your answer mostly on a previous answer is allowed and probably the easiest way to make a solution.
  • You cannot submit two answers in a row. Let someone else post in between.
  • As this challenge requires other competitors to post in the same languages you are, you can only use languages with a free implementation (much as though this were a contest).
  • Note that the victory condition (see below) is designed so that breaking the chain (i.e. making it impossible for anyone else to answer after you via the use of a language that is hard to polyglot with further languages) will disqualify you from winning. The aim is to keep going as long as we can, and if you want to win, you'll have to respect that.

Answer format

As all the answers depend on each other, having a consistent answer format is going to be helpful. I recommend formatting your answer something like this (this is an example for the second link in the chain):

2. JavaScript, 40 bytes

(program goes here)

This program prints 1 in Python 3, and 2 in JavaScript.

(if you want to explain the program, the polyglotting techniques, etc., place them here)

Victory condition

Once there have been no new answers for 14 days, the winner will be whoever posted the second newest answer, i.e. the largest polyglot that's been proven not to have broken the chain. Extending the chain after that is still very welcome, though!

share|improve this question
2  
For people who can see deleted posts: the Sandbox post was here. – ais523 2 days ago
1  
How should permalinks be updated? Should the newest answer contain permalinks of all the previous languages? – Kritixi Lithos 2 days ago
4  
There's no need to copy the previous program, although of course you can use it as a guide; redoing the program from scratch is likely to take longer! There's no need to permalink to answers; sorting by oldest will show all the answers in order already. – ais523 2 days ago
3  
@ais523 I think what was meant was that should new answers contain try it links with the new code? – BlueEyedBeast 2 days ago
3  
I think we need a script that takes a hex dump of the code and automatically runs it in all the languages... – mbomb007 yesterday

24 Answers 24

17. Julia (128 bytes)

#v`16 "<" 6/b0\ .q@#;n4"14""
#>3N9@15o|R"12"*^
#=|
print((1/2and 9 or 13)-(0and+4)^1<<65>>62);# =#;print(17)
#gg99ddi2` |1|1+6

There are two ESCs on the last line, one before the first g and one after the 2. This could be golfed more, but things got messy no thanks to V and Pyth.

Prints 1 in Python 3, 2 in V, 3 in Minkolang, 4 in ><>, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge-93, 11 in Befunge-98, 12 in Fission, 13 in Ruby, 14 in Turtléd, 15 in Haystack, 16 in Pyth and 17 in Julia.


Hints:

  • The start of the fourth line is Python 2/3, Perl, Ruby. The end is Julia, thanks to #= multiline comments (note that Julia doesn't have and/or).
  • V is <ESC>gg99ddi2<ESC>, which is definitely golfable but V is annoying to test on Try it online! since the interpreter is fairly slow.
  • Minkolang and Haystack go down at the first v. Befunge-93 and -98 don't, and depend on a b.
  • Retina counts the number of spaces and 1s in the fourth line, and V hides in the config for Retina (i.e. before the backtick).
  • Per @ETHproduction's hint, Japt uses backticks to hide the majority of the code in a string.
  • Fission is R"12"*.
  • SMBF has been golfed to <. in the first line, plus the final 6.
share|improve this answer
10  
Where has everyone else's code gone though – Alfie Goodacre 2 days ago
4  
159 bytes to 128 bytes? Wow, that's some excellent golfing! – Kritixi Lithos 2 days ago
2  
Nice, 2^7 bytes – tomsmeding 2 days ago
4  
Wow... incredible! We're going to have to write up a new explanation for every language when all's said and done ;-) – ETHproductions 2 days ago
2  
@AlfieGoodacre "You don't have to use the previous answers as a guide to writing your own (you can rewrite the whole program if you like, as long as it complies with the spec)" – mbomb007 yesterday

5. Python 2 (35 bytes)

#3N.;n4
print('1'if 1/2else'5')
#i2

This program prints 1 in Python 3, 2 in Vim, 3 in Minkolang v0.15, 4 in ><> and 5 in Python 2.

Try It Online beta!

In Python 2, 1/2 is 0, which is a falsy value, which makes Python print 5. In Python 3, 1/2 is 0.5, which is a truthy value, which makes Python print 1.

share|improve this answer
    
I can confirm it works in Minkolang – Kritixi Lithos 2 days ago
    
print('1'if 1/2else'5') breaks on my system without a space between 1/2 and else – Tasos Papastylianou yesterday
    
Well, it works with both versions on TIO. – betseg yesterday

10. Befunge, 95 bytes

#v02^0;7||"<+0+0+0+<;n4
#v0#@00
#>3N.
#|\w*
#8
#|
#M`
print(None and 9or 1/2and 1or 5)
#jd5ki2

There is a literal ESC character between j and d on the last line (grr, @ais523). It is not included in this code. To get the actual code, please go to the Try it online link.

This prints 1 in Python 3, 2 in Vim, 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, and 10 in Befunge.

This code shares * with Retina and . with Minkolang and SMBF.

Try it online

Explanation

Actual program

#v02^
    @
    .
    *



    t
    5
#v02^

The last line was written for clarity (Befunge playground is cyclic.)

#

Trampoline, skips v

02^

Push 0 and then 2 in stack and go up.

5t*.@

Push 5, no-op, multiply two elements in stack (2 and 5), print, end program.

share|improve this answer
1  
This makes SMBF print a null byte at the first .. – Pietu1998 2 days ago
    
@Pietu1998 fixed! – JHM 2 days ago
    
Hey, it wasn't me who chose to use a language where many of the most important commands are nonprintable characters… (In other news, I was considering Befunge as a strong possibility for adding to this polyglot; it seems to fit in well with the other languages. I like the way you did it, although it may well need modifying to fit in more.) – ais523 2 days ago
    
@ais523 I agree that modifying this code may be difficult. To alleviate this, I put in some 0s to indicate that those characters can be anything (except the "<+0+0+0+<;n4 part) and parts of the Befunge code may be moved around. And a tip for the next person: most of characters are no-op in Befunge, so adding more lines is not likely going to affect the Befunge code. – JHM 2 days ago
    
Thinking about making a befunge-98 (or other similar funge) submission, because they add a fair amount of operations that are no-ops in regular '93. It might be hard to fit though, and I would need to figure out how all the other languages worked so I could work around them... – Mistah Figgins 2 days ago

11. Befunge 98, 102 bytes

#v;2^0;7||"<+0+0+0+<;n4
#v0#_q@
#>3N.
#|\w*
#8  ^1b0<
#|
#M`
print(None and 9or 1/2and 1or 5)
#jd5ki2

Prints:

To be perfectly honest, I have no clue why the Vim code takes 1 min to output. Also, no clue how Retina works.

Explanation:

#v          Skips the v, which would send the IP down
  ;         Unlike '93, where ; is a no-op, '98 skips to the next ;
            and doesn't execute anything in between
   2^0;     Not executed, unlike Befunge 93
       7|   Pushes 7 onto the stack, and then sends the IP up, because 7 is not 0
n0b1        n clears the stack, and #s are pushed until the stack is [0, 11, 1
    *.      multiplies the top 2 values of the stack to give 11, and prints it (yay!)
      _     Sends the IP right, because the top value of the stack is 0
       q    Ends the program (no-op for '93, which continues to @)

Things to note:

  • The 0 next to the b isn't strictly necessary in the code's current state, and the stack has been cleared. It can be removed if necessary, but allows for other stack manipulation beforehand as part of a possible future program.
  • The _q@ is there as part of Retina (It doesn't work without it, don't ask me why). The addition of q also lets the '98 code run a t operation, which splits the IP (along with making the Retina program print 8 instead of 7)
  • The _ is not a simple > because that would mess the SMBF part up.

Edit: Just realized that the _q@ should probably be @00 (Where 0s can be ~any char) to make the program more flexible in the future. I'm too lazy (and tired) to change all the links right now though. Will get around to it eventually...

Edit 2: I Didn't expect 6 more answers this quickly. I guess it's staying as is. Great job everyone!

share|improve this answer
    
Heh, I wrote my 11th answer, only to realise that it had already been posted, now I changed it to the 12th answer :) – Kritixi Lithos 2 days ago
    
Thank you for adding all the TIO links! Really helpful! – Dom Hastings 2 days ago
    
Wow! Awesome!!! – JHM 2 days ago
    
Any Idea why Vim takes so long to execute? – Mistah Figgins 2 days ago
    
@MistahFiggins I guess it is because the code has to be converted to keystrokes, but other than that, I have no clue – Kritixi Lithos 2 days ago

20. Prelude, 167 bytes

#v`16 "<" 6/b0\ .q@#;n4"14""
#>3N9@15o|R"12"*^*ttt*~++%
#=|
print((1/2and 9 or 13)-(0and+4)^1<<65>>62);#35(99999+++++!) =#;print(17)
#       ~nJ<
#
#gg99ddi2` |1|1+6

Literal ESC characters in the same place as in the previous submissions (between the # and g, and between the 2 and `, on the last line), because you can't take Vim out of insert mode with printable characters.

This program prints 20 in Prelude, 19 in Reng (testable here), 18 in Cardinal, 17 in Julia, 16 in Pyth, 15 in Haystack, 14 in Turtlèd, 13 in Ruby, 12 in Fission, 11 in Befunge-98, 10 in Befunge-93, 9 in Perl, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in Vim/V, 1 in Python 3, and a partridge in A Pear Tree.

The existing code pretty much cancels itself out in Prelude, consisting only of while loops with falsey arguments and some stack manipulation on stacks we don't care about. Even better, there's a spot in the code that's a comment in all the languages that have them (between the # and =# of the previous submission). The hard part of fitting Prelude into this was generating numbers with only one stack and without blowing up the byte count. This program uses a loop that adds 45 to every stack element and outputs it as ASCII, thus by placing a 5 above a 3 on the stack, we get 20 as output. (Neatly, 20 is an easier number to output than 19 is in Prelude, so answer 19 being posted actually helped me a bit.)

share|improve this answer
    
Prelude should be fairly easy to work into future programs. Some advice for anyone it may happen to cause trouble to: don't let parentheses line up vertically; make sure you don't allow exclamation marks outside parentheses; and once you've placed digits outside parentheses, don't place more parentheses further right on the same line. The gap which I put the Prelude program into is still open, and looks like it might be a fruitful place for other 1D languages to go (Prelude's sort-of 1½D, and acts more like a 1D language in this program). – ais523 yesterday
    
Nice, beat me to the punch with Prelude :) I actually think ASCII-only V might be possible with :%s replace, but even then it's a little tricky (and V is annoying to test) – Sp3000 yesterday
    
If you use a : to start a command in vim, you're gonna need a carriage return, which also happens to be unprintable. :/ – Zwei yesterday

3. Minkolang v0.15 (26 bytes)

#>>>>>>>>v
print(1)#>3N.i2

This program prints 1 in Python 3, 2 in Vim, and 3 in Minkolang v0.15

I hope I don't mess things up by introducing a 2d language

Try it online!

Explanation

#                     stops program from moving through time (really does nothing)
 >>>>>>>>             I can't use a space because then the program will move through time
         v            go down
         >            go right
          3N.         Outputs 3 and end program
                      Anything afterward is ignored since program has ended

Vim somehow ignores Minkolang, so that's good

And there really wasn't a problem with Python since it ignores the comments #

Next...

For the next language, I suggest something like ><> since # acts as a reflector (so that the direction will change to left and it will wrap to all the way in the right) so you can add code that can be ignored by other languages

share|improve this answer
1  
“move through time” wat? – TùxCräftîñg 2 days ago
    
@TùxCräftîñg Minkolang has 3 dimensions (2d = normal, the 3rd one is time). TBH, I don't understand it, it just states that in the explanation on the TIO link – Kritixi Lithos 2 days ago
    
@mbomb007 What exactly are you referring to? – Kritixi Lithos 2 days ago
    
@mbomb007 4th submission (><>) already posted :) – Kritixi Lithos 2 days ago
    
@KritixiLithos I posted ><> without even reading you're suggestion. It's such a good choice for this sort of thing – BlueEyedBeast 2 days ago

15. Haystack (141 bytes)

#v;2^0;7||"<+0+0+0+<*!2'!1'L#'1r'4;n4
#v0#_q@
#>3N.15o|1
#|\w*
#8  ^1b0<
#|
#M`
print ((0 and'13')or(None and 9 or 1/2 and 1 or 5))
#jd5ki2

Note: there is an ESC after o in the third line and after j in the last line

This prints 1 in Python 3, 2 in Vim, 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge, 11 in Befunge-98, 12 in Fission, 13 in Ruby, 14 in turtlèd, and 15 in Haystack.

Try it online!

Explanation

#v                           go down
 v
 >                           go right
  3N.                        does nothing important
     15o|                    outputs 15 and ends program
                             there is an <ESC> after 'o' since 'o' in Vim enters insert mode
         1                   I added this to satisfy Retina
share|improve this answer
    
Awesome, thanks for checking out Haystack! :) – Kade 2 days ago
    
@Kade It's a nice 2D language, an online interpreter would be more helpful (although I have already downloaded the Python interpreter) :) – Kritixi Lithos 2 days ago
    
@Kade There is a TIO link for haystack now! – Kritixi Lithos yesterday
    
@MistahFiggins The link works for me and outputs 15 – Kritixi Lithos yesterday
    
@MistahFiggins Cache? Because it works for me without any problems or any error messages – Kritixi Lithos yesterday

4. ><> (29 bytes)

#>>>>>>>>v;n4
print(1)#>3N.i2

This program prints 1 in Python 3, 2 in Vim, 3 in Minkolang v0.15 and 4 in ><>

Try it Online!

Code ran

#             - change direction to left
            4 - add 4 to stack
           n  - print as a number
          ;   - end the program

Yet another 2D language.

Has no effect on Minkolang as it adds characters after the direction changes, gets ignored by Vim for some reason. # is a comment in Python so no change their either.

share|improve this answer

6. SMBF, 45 bytes

#v<++++<;n4
#>3N.
print('1'if 1/2else'5')
#i2

Try it online

This program prints 1 in Python 3, 2 in V, 3 in Minkolang v0.15, 4 in ><>, and 5 in Python 2.

SMBF (aka Self-modifying Brainfuck) uses <++++<>.. The pointer is moved left (to the last character of the source code), and the cell is incremented four times then printed.

share|improve this answer
1  
I think you need another + in the code and TIO link. – Riley 2 days ago
    
@Riley It's been fixed. – mbomb007 2 days ago

21. Nim (161 bytes)

#v`16/"<"6/b.q@#;n4"14""
#>3N6@15o|> ^*ttt*~++ %
#=~nJ<R"12";
#[

print((1/2and 9 or 13)-(0and+4)^1<<65>>62)#46(89999+++++!)=#print(17)#]#echo 21
#8dggi2` |1|6

Two <ESC>s, between 8d and between 2` on the last line. You can tell that my previous one was golfed in a hurry, because I woke up this morning and realised I could take a bunch more off. I had 152 bytes but that seems to only work in Perl 5.24.0, so in the interest of compatibility with TIO I've kept the original expression for now.

Prints 1 in Python 3, 2 in V, 3 in Minkolang, 4 in ><>, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge-93, 11 in Befunge-98, 12 in Fission, 13 in Ruby, 14 in Turtléd, 15 in Haystack, 16 in Pyth, 17 in Julia, 18 in Cardinal, 19 in Reng, 20 in Prelude and 21 in Nim.

Note that Nim on ideone.com uses version 0.11.2, which is a tad too old, since this program relies on #[ ... ]# multiline comments added in early 2016.

Thanks to Cardinal's Windows interpreter, my workflow now consists of two laptops and a Python http.server in between.


Edit — some more hints:

  • The 8 at the start of the last line is to set Retina's limit to the first 8 matches, otherwise without it Retina would output 2. Note that this means the final line regex only needs to match at least 8 times in the second last line now, as opposed to exactly 8 — during my meddling I modified Prelude to get Retina right, but it turned out that was unnecessary in the end.
  • The mismatched quote at the end of the first line is so that Pyth doesn't complain about invalid syntax for the rest of the code.
  • If you modify the second line you might have to change the 6@ for Minkolang, which makes the pointer jump 6 spaces to land on the ^.
  • There's a pair of [] now, so SMBF needs to be on a 0 cell before it hits the [, or alternative the interior needs to clear the cell.

There's probably more to golf (even now I see a stray space before the % for Cardinal), but I should really stop golfing in the wee hours of the morning.

share|improve this answer
1  
TIO now supports Cardinal – Mistah Figgins 23 hours ago

13. Ruby (129 bytes)

#v;2^0;7||"<+0+0+0+<*!2'!1'L;n4
#v0#_q@
#>3N.
#|\w*
#8  ^1b0<
#|
#M`
print ((0 and'13')or(None and 9 or 1/2 and 1 or 5))
#jd5ki2

Please note the literal Esc character on the last line between the j and d, as per ais523's Perl answer.

Try it online!

This prints 1 in Python 3, 2 in Vim, 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge, 11 in Befunge-98, 12 in Fission and 13 in Ruby.

Just a minor modification to the existing print statement to abuse the fact that 0 is truthy in Ruby. I had to add some spaces to the other statements to make it parse correctly.

share|improve this answer

16. Pyth (159 bytes)

#v\;2^0\;7||"<+0+0+0+<*!2'!1'L#'1r'4;n4
#v0#_q@
#>3N.15o|1
#|\w*
#8  ^<1b0 <
#|
#M`
print ((0 and'13')or(None and 9 or 1/2 and 1 or 5))
#"07|5//00;16 "jd5ki2

Note: there is an ESC byte (0x1B) after the o in the third line and after the j in the last line.

This was quite a fun experience. Japt and Pyth are both golfy languages, but Japt is infix and Pyth is prefix, and Pyth auto-requests input and fails if arguments are missing.

Before the Haystack answer I had an almost-working solution using #, which gets a char code in Japt and loop-until-error in Pyth. Pyth happens to be very useful in polyglots, since the common comment char # essentially works as an error silencer.

When I got home I managed to find a this piece of code that worked in both using //, which works as a comment in Japt and two divisions in Pyth. Then it was just a matter of getting the Befunges to route correctly.

This is very unlikely to be optimal, but it's good enough for now. I tried to test them all, but I'd highly appreciate someone double checking that the outputs match.

Prints 1 in Python 3, 2 in V, 3 in Minkolang, 4 in ><>, 5 in Python 2, 6 in Self-Modifying Brainfuck, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge(-93), 11 in Befunge-98, 12 in Fission, 13 in Ruby, 14 in Turtléd, 15 in Haystack, and

16 in Pyth.

Explanation

What Pyth sees here is:

#v\;2^0\;7||"string
multiline
string"07|5//00;16 "string

This translates to the following pseudocode:

while no errors occur:
    evaluate ";"
    print 2
    print 0 to the power ";"
    print 7
    print "string\nmultiline\nstring" or 0 or 7
    print 5 or 0 divided by 0 divided by (missing)
print 16
do nothing with "string"

The first loop exits on trying to evaluate ; which isn't a valid expression. Then Pyth just prints 16.

share|improve this answer
    
Extending in what way? I still need another 5 or so bytes available for my answer ;) – Alfie Goodacre 2 days ago
    
@AlfieGoodacre By adding the rest of the details to the post. I just wanted to remain sane and thus posted my code before anyone stole my place. :D – Pietu1998 2 days ago

14. Turtlèd (135 bytes)

#v;2^0;7||"<+0+0+0+<*!2'!1'L#'1r'4;n4
#v0#_q@
#>3N.
#|\w*
#8  ^1b0<
#|
#M`
print ((0 and'13')or(None and 9 or 1/2 and 1 or 5))
#jd5ki2

This prints 1 in Python 3, 2 in Vim, 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge, 11 in Befunge-98, 12 in Fission, 13 in Ruby and 14 in Turtlèd.

First line added #'1r'4 near the end of line, Turtled takes #[string]# as string input then 'X places the value of x on the grid, r moves right 1 space on the grid. The value on the grid is printed at the end of the program implicitly.

Try it Online

Link to Turtled docs

share|improve this answer
    
@Sp3000 - edited and fixed (should be) – Teal pelican 2 days ago
    
    
hooray! My language is used. Also it has a capital t, unlike brainfuck – Destructible Watermelon yesterday
    
@DestructibleWatermelon It's a fun little language for some challenges :) I saw you post a while back and thought I'd pick it up just in case. – Teal pelican yesterday

2. Vim (11 bytes)

print(1)#i2

This program prints 1 in Python 3, and 2 in Vim.

Just to get the ball rolling and to throw my favorite language into the mix early on. :)

It's a very straightforward answer.

print(1)#

just so happens to be a NOP in vim. (lucky for me) Then i2 enters insert mode and inserts a '2'. You can try vim online here

Of course, in python

print(1)

prints '1', and

#2

is a comment.

share|improve this answer
1  
Is this V or Vim? The interpreter you linked to is technically "V". – mbomb007 2 days ago
    
@mbomb007 Well, V is almost entirely backwards compatible, so the intention was vim. I suppose it technically is V though. Is it too late to change? – DJMcMayhem 2 days ago
    
Not really, just edit the title in the answers. – mbomb007 2 days ago
    
Does V have a way to exit Insert Mode? – mbomb007 2 days ago
1  
@mbomb007 A literal ESC character will do it (which is why I had to use one in my submission). – ais523 2 days ago

23. Hexagony, 186 bytes

Sorry if this messes up plans...

#v`16/"<"6/b.q@"(::):::  (22)S#;n4"14"
#>3N6@15o|> ^*ttt*~++~~~%
#=~nJ<R"12";
#[

print((1/2and 9 or 13)-(0and+4)^1<<65>>62)#46(89999+++++!)=#print(17)#0\32=""<0]#echo 21
#8␛dggi2␛` |1|6

␛ is used to represent a literal ESC character.

Prints:

23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (testable here), 18 in Cardinal, 17 in Julia, 16 in Pyth, 15 in Haystack, 14 in Turtlèd, 13 in Ruby, 12 in Fission, 11 in Befunge-98, 10 in Befunge-93, 9 in Perl, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in Vim/V, and 1 in Python 3.

To get to the unlinked languages, click the change language button in the upper right of the Hexagony link.


Hexagony isn't readable (at ALL) in this format. We need to look at it in hexagonal form.
Note that the 2 ESC characters have been replaced with s so you can see them - they are ignored, so there are no others in the program:

        # v 1 6 / " < " 6
       / b . q @ " ( : : )      A lot more readable, right?? No?
      : : : ( 2 2 ) S # ; n
     4 " 1 4 " # > 3 N 6 @ 1
    5 o | > ^ * t t t * ~ + +
   ~ ~ ~ % # = ~ n J < R " 1 2
  " ; # [ p r i n t ( ( 1 / 2 a
 n d 9 o r 1 3 ) - ( 0 a n d + 4
) ^ 1 < < 6 5 > > 6 2 ) # 4 6 ( 8   | Note that the 0s below can be replaced
 9 9 9 9 + + + + + ! ) = # p r i    | With anything (except "`" or " "), 
  n t ( 1 7 ) # 0 \ 3 2 = " " <     V as far as Hexagony is concerned
   0 ] # e c h o 2 1 # 8 ␛ d g
    g i 2 ␛ | 1 | 6 . . . . .    <-- the ␛ represents an esc
     . . . . . . . . . . . .         character
      . . . . . . . . . . .
       . . . . . . . . . .       A "." is a no-op
        . . . . . . . . .
                ^
                | Mirror wraps to here, going NW

For those unfamiliar with Hexagony, There are 6 IPs, which start at the 6 corners. Only 1 is active at a time, and are switched by using #][. The memory model isn't that important to this program, but might be necessary to understand in the future. All that you need to know is that 1 int is stored in a "memory edge" (ME for short), and '"}{ change the ME that is active.

\/|_>< are mirrors that control program flow.

This is how it works:

First line executed:

#       A no-op (sets active IP to 0, the currently active one)
 v      letter chars set the ME to their ASCII value - so ME is now 118
  16    Like Labyrinth, 0-9 multiplies ME by 10 and is added - ME now 11816
    /   A mirror that sends IP going NW by wrapping to the bottom

The bottom (snippet flipped vertically so you can read up to down):

    .   
   .    A series of no-ops. The IP is going NW now,
  .     because of the mirror on the top.
 .
|       Another mirror. This one sends the IP NE, into the h
 h      sets the ME to 104, the ASCII value for h
  #     104 % 6 == 2, so IP 2 is now active instead of 0

The right edge:

        8  IP #2 is moving SW, starting in the right corner 
       i   Sets the ME to 105
      <    Mirror. Sends the IP going due West
    ""     These change the Active ME - just know that the new edge is 0
   =       Changes the MP (more in specs) - effectively a no-op used to fill space
\32        pushes 23, and mirrors up NE to the !

The last bit of relevant code:

!          Prints the current value of the ME as an int. Success!
 20(R~     Does things to the ME - irrelevant now
      @    Ends the program!

Things to note:

  • Hexagony drops all s and `s before executing, so any changes to those will not affect Hexagony
  • I needed to pad the code so that it would be interpreted as a 9 length hexagon, instead of an 8th - be careful golfing below 169 or above 217 relevant characters
  • Because of this, the ~~~ and the 2 0s at the end can be changed at no harm to the code
  • The ="" just moves the ME away from the previous one so that a new ME can be modified. They can be replaced with other characters that do the same thing at no harm to the hexagony program ('s, for example)
  • This is technically not comlient with the Befunge 93 specs, because it limits the bounding box of the code to 80 by 25 chracters. However, Most interptreters ignore this spec (like TIO), So I don't personally think it's that big of a deal. If you do, feel free to leave a comment. (If enough really want me to change it, then I will try)
  • Hope it's not too hard now.
share|improve this answer
    
This could easily become the most crazy program flow if done right. I was close to getting it done with a size 8 hexagon through some crazy @## method, but 9 was a lot easier once I tried that. Also, v1 of TIO works a lot faster, but you can't switch languages easily. – Mistah Figgins 13 hours ago
    
I would suggest Labyrinth next, but I want to do that one. – Mistah Figgins 13 hours ago
    
I'm not skilled enough to write anything like this myself, but in the mean time I'm waiting for Cubix to pop up. – Pavel 12 hours ago
    
@pavel I'm not familiar with that language. I assume it's 3D. Sounds cool. There's also some funges that are 3D, might be an interesting addition – Mistah Figgins 12 hours ago
    
I suspect it's easiest to maintain something like this flow as long as we're still at this side length, and just rewrite the Hexagony code when we go up to the next size. With respect to 3D languages, Trefunge should be fairly easy to fit in, assuming that none of the existing languages panic upon seeing formfeeds. (Also, Cubix was posted earlier but deleted because the poster thought it might be too hard; maintaining Hexagony and Cubix at once could be fairly confusing…) – ais523 10 hours ago

7. Japt (50 bytes)

#v;7||"<++++<;n4
#>3N.
print('1'if 1/2else'5')
#i2

Man, it was fun to fit Japt in there. Hopefully it didn't kill anyone's plans...

Test it online!

This program prints 1 in Python 3, 2 in V, 3 in Minkolang v0.15, 4 in ><>, 5 in Python 2, and 6 in SMBF.

How this works: #v; takes the char code of v, or 118. Then 7|| returns the logical OR of 7 and the rest of the code, which is wrapped in a string with " to avoid any syntax errors. The result, 7, is automatically sent to STDOUT.

For future polyglotters, " can be changed to ` at no penalty to the Japt program (though I'm not sure about the others).

share|improve this answer

8. Retina, 70 bytes

#v;7||"<+0+0+0+<;n4
#>3N.
#|\w*
#8
#|

#M`
print('1'if 1/2else'5')
#i2

Try it online

This program prints 1 in Python 3, 2 in V, 3 in Minkolang v0.15, 4 in ><>, 5 in Python 2, 6 in SMBF, and 7 in Japt.

Screw creating hyperlinks to interpreters. That's going to take way too much time. It's up to the poster and anyone creating new answers to test it yourself.

Explanation:

#v;7||"<+0+0+0+<;n4     # replace every empty string with "#>3N."
#>3N.
#|\w*                   # replace words chars with "#8"
#8
#|                      # remove all "#". The "|" is something I could've golfed off.

#M`                     # match all places between characters (finds 8)
print('1'if 1/2else'5') # replace something that won't be found. noop
#i2
share|improve this answer
    
This is 2 bytes too long (50 + 20 is 70, 50 + 20% is 60). – ais523 2 days ago
    
@ais523 Fixed it. – mbomb007 2 days ago
2  
Care to provide an explanation? If not, that's ok. – Mistah Figgins 2 days ago
    
@MistahFiggins Sure. Added. – mbomb007 2 days ago

19. Reng, 152 bytes

#v`16 "<" 6/b0\ .q@#;n4"14""
#>3N9@15o|R"12"*^*ttt*~++%
#=|
print((1/2and 9 or 13)-(0and+4)^1<<65>>62);# =#;print(17)
#       ~nJ<
#
#gg99ddi2` |1|1+6

I added another #\n so that retina would cooperate. Here's how it works:

# redefines v to push 0, the default TOS. Then, it negates the TOS (`), pushes 1 and 6, the character of <, pushes 6 again, and mirrors upwards with /, colliding with the other `, which negates the 6. Then, it hits the <, pushes J (base 36 for 19), then outputs it as a number, finally terminating (~).

Escapes in between 2 and `; and # and g.

  1. Try it online!—Python 3
  2. Try it online!—V
  3. Try it online!—Minkolang
  4. Try it online!—><>
  5. Try it online!—Python 2
  6. Try it online!—SMBF
  7. Ethproductions—Japt
  8. Try it online!—Retina
  9. Try it online!—Perl
  10. Try it online!—Befunge 93
  11. Try it online!—Befunge 98
  12. Try it online!—Fission
  13. Try it online!—Ruby
  14. Try it online!—Turtléd
  15. Try it online!—Haystack
  16. Try it online!—Pyth
  17. Try it online!—Julia
  18. Try it online!—Cardinal
  19. JSFiddle—Reng
share|improve this answer

9. Perl, 84 bytes

#v;7||"<+0+0+0+<;n4
#>3N.
#|\w*
#8
#|

#M`
print(None and 9or 1/2and 1or 5)
#j␛d5ki2

There's a literal ESC character in the actual code between the j and d; it has been replaced with a ␛ here for visibility.

This prints 1 in Python 3, 2 in Vim (tested locally, but here's a link for the very similar language V), 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, and 9 in Perl.

Let's get some more exoteric languages in, via abusing arithmetic that works differently in different languages. (None is falsey in Python but truthy in Perl, and and/or chains work the same way in both languages.)

Apart from Python, I also had to change the vim code. Instead of making it into a series of no-ops, I just let it insert junk, then deleted the junk again at the end.

share|improve this answer
2  
Seriously? You're going to make it extremely difficult for anyone else to create answers if you put in a literal ESC. We have to be able to test the code. – mbomb007 2 days ago
    
You don't have to include the literal ESC in your own answers; I just found it to be the easiest way to write this one. (Additionally, it works fine in Firefox, and in local testing; the only thing blocking me from putting it in the post is that Chromium, which I use for SE, doesn't want to put it into the input box.) – ais523 2 days ago
    
Also, you can't test locally for Vim. Languages are defined by the interpreter that is used. So it's really V that we've had all this time. – mbomb007 2 days ago
1  
Err, isn't vim an interpreter for Vim? (It works in both vim and V, though.) – ais523 2 days ago
4  
@ais523 maybe you can put ␛ to represent the 0x1B byte? – betseg 2 days ago

18. Cardinal, 137 bytes

#v`16 "<" 6/b0\ .q@#;n4"14""
#>3N9@15o|R"12"*^*ttt*~++%
#=|
print((1/2and 9 or 13)-(0and+4)^1<<65>>62);# =#;print(17)
#gg99ddi2` |1|1+6

Literal escape chars between # and g, and 2 and `.

Prints:


Edit: Fixed esc character between o and | - don't know why it was there in the first place.

share|improve this answer
    
Bytes cannot be fractions, so the limit was really floor(128 * 1.2), so good thing you didn't need another byte. – mbomb007 yesterday
    
Also, this is incorrect, as it prints 6\x00 in SMBF. (There are two . characters.) – mbomb007 yesterday
    
Can we get the SMBF to modify out the second period? – Pavel yesterday
    
Oh right, forgot about the second period. Shoot. – Mistah Figgins yesterday
2  
@ais523 It was deleted for a little while, but it should be fixed now. As far as I know, it works with all 18 languages... – Mistah Figgins yesterday

22. Underload (stringie), 173 bytes

#v`16/"<"6/b.q@"(::):: :(22)S#;n4"14"
#>3N6@15o|> ^*ttt*~++ %
#=~nJ<R"12";
#[

print((1/2and 9 or 13)-(0and+4)^1<<65>>62)#46(89999+++++!)=#print(17)#]#echo 21
#8dggi2` |1|6

As before, there's a literal ESC character immediately after each of the 8 and 2 on the last line.

This program prints 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (testable here), 18 in Cardinal, 17 in Julia, 16 in Pyth, 15 in Haystack, 14 in Turtlèd, 13 in Ruby, 12 in Fission, 11 in Befunge-98, 10 in Befunge-93, 9 in Perl, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in Vim/V, and 1 in Python 3.

stringie is the Underload interpreter used by Try It Online! Fortunately for polyglotting, it ignores non-command characters rather than crashing on them, so the main thing to ensure is that there are enough stack elements that we don't get an empty stack crash (done here with (::):::; the code probably doesn't actually need that many colons, but I added them anyway as padding to remove awkward vertical alignments). Because it had to appear fairly early (it needs to be before any instances of aS^:*~!), I placed the Underload code on the first line; thanks for Sp3000 for suggesting a place where it would fit safely.

I needed to leave an additional space on the first line because Cardinal doesn't like : lined up with %; I also needed to structure the Underload code to avoid parentheses lining up with each other vertically (which Prelude dislikes). Pyth was the hardest language to get working, and I needed to resort to advice from Sp3000 there (who suggested moving the double quotes around; this combination works). In an earlier version of the code, the Underload was further to the right, but that got in the way of Turtlèd.

The space immediately after the Underload (i.e. after the S of (22)S should still be safe; the Underload doesn't change that. In order to avoid causing problems for Underload, ensure that your code has matched parentheses, avoids S, and isn't intelligible enough as Underload code to cause problems in its own right. (::) has a tendency to breed once it's placed on the stack (I intentionally wanted to write the Underload in a fairly robust way to make continuing the chain easier), so most random sequences of non-S characters will be safe from here, but it's possible to defeat the "ignore the rest of the program" if you try hard enough. If you need an S for some reason, try ensuring that some pair of parentheses captures it; that'll cause Underload to treat it as data rather than code and avoid producing stray output.

share|improve this answer
    
Any hints on where 1 or 2 characters (other than spaces) can be added later in the program? I'm trying to do a hexagony submission, so it's ok if it has to be certain characters, as long as it isn't just white space. The addition of all the :s means that I have to route program flow around them so they don't cause divide by 0s – Mistah Figgins 17 hours ago
    
@MistahFiggins: How late do you need them? Immediately after print(17)# is a location that every language with block comments, and every 2D language, currently ignores, so as long as you add characters that are safe for the languages which parse everything, you should be OK. Digits should hopefully be a pretty harmless thing to use if you just want some sort of padding and don't care what it is. – ais523 16 hours ago
    
This will work, thanks! There are 22 languages now, so it's a little hard to keep track of what's run in which language. – Mistah Figgins 16 hours ago

1. Python 3 (8 bytes)

print(1)

This program prints 1 in Python 3.

Starting this off with Python 3 because I know it's good for polyglots and can be taken in a number of different directions (also, I wanted to ensure that the first answer was in a relatively normal language, rather than an absurd esolang that's hard to polyglot with).

share|improve this answer
    
Would ><> be a good choice for the 2nd language (so that we start 2d space)? – Kritixi Lithos 2 days ago
    
So that means the next answer can't be more than 9 bytes? That's gonna be really hard to come up with another one. – DJMcMayhem 2 days ago
1  
@DJMcMayhem Each answer must be no more than 20% or 20 bytes (whichever is larger) longer – Kritixi Lithos 2 days ago

12. Fission (110 bytes)

Just adding yet another 2d lang... Streak of 3 2d-langs in a row, let's keep it moving folks!

#v;2^0;7||"<+0+0+0+<*!2'!1'L;n4
#v0#_q@
#>3N.
#|\w*
#8  ^1b0<
#|
#M`
print(None and 9or 1/2and 1or 5)
#jd5ki2

This prints 1 in Python 3, 2 in Vim, 3 in Minkolang, 4 in <><, 5 in Python 2, 6 in SMBF, 7 in Japt, 8 in Retina, 9 in Perl, 10 in Befunge, 11 in Befunge-98, and 12 in Fission.

Try it online!

Explanation

The only important piece of code is the first line

                These are the important bits
                    >------<
#v;2^0;7||"<+0+0+0+<*!2'!1'L;n4
                           ^
                   we start here by creating an atom moving Left
           (I could not use R for Right since that means Replace in Vim)

                       1'          sets the atom's mass to the ASCII value of '1'
                      !            outputs the atom's mass (as a character) 
                    2'             sets the atom's mass to the ASCII value of '2'
                   !               outputs it
                  *                program terminates

Next...

If Fission is causing trouble, remember, you can move the Fission code anywhere you want, since the start of the program is only identified by the commands that create atoms, and the program ends whenever the atoms are destroyed.

You can also change the atom's start direction to suit your needs, R for Right (but Vim will interpret that as Replace), U for Up, D for Down (or Deletes entire line in Vim, can be useful).

share|improve this answer
    
This answer doesn't work with the Befunge93 answer, it only produces a 0 not 10. – Teal pelican 2 days ago
1  
@Tealpelican Works for me. Did you remember the ESC character between j and d on the last line? See the TIO link. – Zgarb 2 days ago
    
@Tealpelican tio.run/nexus/… – Kritixi Lithos 2 days ago
1  
Yeah my bad, for some reason chrome was removing it for me. – Teal pelican 2 days ago

24. Numberwang, 212 bytes

#v`16/"<"6/b.q@"(::):::  (22)S#;n4"14"
#>3N6@15o|> ^*ttt*~++~~~%
#=~nJ<R"12";
#[

print((1/2and 9 or 13)-(0and+4)^1<<65>>62)#46(89999+++++!)=#print(17)#0\32=""<0]#echo 21
#8␛dggi2␛` 07775340574099127127003993|1|6

Note: there are two literal ESC characters in this code, before and after dggi2 in the last line. They have been replaced with ␛ for visibility.

This code prints 24 in Numberwang, 23 in Hexagony (test it here), 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (here), 18 in Cardinal, 17 in Julia, 16 in Pyth, 15 in Haystack, 14 in Turtlèd, 13 in Ruby, 12 in Fission, 11 in Befunge-98, 10 in Befunge-93, 9 in Perl, 8 in Retina, 7 in Japt (here), 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in Vim/V, and 1 in Python 3.

To test it, take only the digits (non-digit characters are ignored), do the following replacements, and use the Brainfuck interpreter (here's a Numberwang to BF translator):

{"6[digit]" -> "+++ ... (length digit)", "5[digit]" -> "--- ... (length digit)"}

Then:

{"0" -> ">", "1" -> "<", "9" -> "+", "2" -> "-", "3" -> ".", "8" -> ",", "4" -> "[", "7" -> "]"}

The actual code (translated to BF):

<++++++--[<[.+--<-+<.>[<+++++++[++++++++++++<]>.->-<,->]]]---[>-------[>++<-]<-]>>.++.<6

Try it!

Things to note

  • The 4s and 7s must match up (They are brackets in Numberwang). I added three 7s in the last line for that reason.

  • There is an extra 6 (before 777 in the last line) to make Hexagony work.

  • You might go insane while adding another language.

share|improve this answer
    
Someone else do the rest in my edit messsage - clearly needed, as I started messing up! – Riking 10 hours ago
    
@Riking: Right, your edits are useful, but try to be a bit more careful; you placed the in the wrong place in one and I had to re-edit to move it. – ais523 10 hours ago
1  
I don't think you can use a BF interpreter to test Numberwang code since the BF interpreter won't run 5s and 6s. Also the language seem awfully ambiguous with regard to 5s and 6s, and I can't check my interpretation of the spec because the HW example on Esolangs won't run since there's one more 7 than 4. – Sp3000 5 hours ago
    
Okay, I think 67 is parsed together so that it's not a bracket, which makes the rest of the 4s/7s match up. 6/5 seem to increment/decrement the value of the current pointer, and the HW example needs more 9s for outputting. Now I'm very convinced this answer isn't valid as-is, and I don't think this Numberwang is allowed since there wasn't an interpreter for it before the challenge. – Sp3000 4 hours ago
    
@Sp3000 Whoops deleting answer for now. The 66 part also causes problems. – JHM 4 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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