Add a language to a polyglot

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

    Note: This has become quite a long-lasting challenge, and posting new answers is fairly difficult. As such, there's now a chat room available for this challenge, in case you want advice on a particular part of a potential answer, have ideas for languages that could be added, or the like. Feel free to drop in if you have anything to ask or say!

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

    • The output must be only the integer, but trailing newlines are OK. Other unavoidable stdout output is also allowed. Examples: interpreter name and version in Befunge-93,
      space after printed string in Zephyr. Some languages provide two methods of printing – with and without
      trailing space; in this case method without trailing space must be used.

    • 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. This rule applies until victory condition is met.

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

    • In the case where a language has more than one interpreter, you can pick any interpreter for any given language so long as all programs which are meant to run successfully in that language do so in that interpreter. (In other words, if a program works in more than one interpreter, future posts can pick either of those interpreters, rather than a post "locking in" a particular choice of interpreter for a language.)

    • This challenge now uses the new PPCG rules about language choice: you can use a language, or a language interpreter, even if it's newer than the question. However, you may not use a language/interpreter that's newer than the question if a) the language was designed for the purpose of polyglotting or b) the language was inspired by this question. (So newly designed practical programming languages are almost certainly going to be OK, as are unrelated esolangs, but things like A Pear Tree, which was inspired by this question, are banned.) Note that this doesn't change the validity of languages designed for polyglotting that are older than this question.

    • 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!

    The winner is Chance, see answer 194 (TemplAt).

    Language list

    // This snippet is based on the snippet from hello world thread
    // It was tested only in Google Chrome

    if (!String.prototype.format) {
    String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, (match, number) => (typeof args[number] != 'undefined' ? args[number] : match) );

    var QUESTION_ID = 102370; // from the question url
    var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";

    function answersUrl(index) {
    return "" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;

    var answers = [], answer_page = 1;

    function getAnswers() {
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
    answers.push.apply(answers, data.items);
    if (data.has_more) { $('#status').text($('#status').text() + '.'); getAnswers(); }
    else process();
    // [Documentation]( states that `error` handler is not called for cross-domain JSONP requests,
    // but it works here, probably because and are on the same domain.
    error: function (a,b,c) {
    $('#status').text( "Failed to load answers: " + b + " " + c );
    console.log( b + " " + c );


    const input = document.querySelector('input');
    input.addEventListener('input', onSearchInput);

    function onSearchInput(e)
    var table = document.getElementsByTagName("table")[0];
    var str = e.srcElement.value.toLowerCase();
    var num_results = 0;

    if(str == "") // optimization for empty input
    // show all rows
    for(var i = 1, row; row = table.rows[i]; i++)
    row.className = "";
    for(var i = 1, row; row = table.rows[i]; i++)
    var hidden = row.innerText.toLowerCase().indexOf(str) == -1;
    if(!hidden) num_results++;
    row.className = hidden ? "hidden" : "";
    document.getElementById("results").innerText = "Results: " + num_results;

    /* Function ParseHeader() extracts answer number, language name and size of polyglot from answer header.
    Argument: `header` - answer header string without markup, eg. "1. Python 3 (8 bytes)" or "59. Tcl, 1324 bytes".
    Retval: object, eg. {num: 1, language: "Python 3", size: 8} or
    null if header has wrong format

    There are two formats of header, new one with comma and old one with parens.
    Parsing new format only with regexp is hard because:
    - language name may contain commas, eg. "51. Assembly (x64, Linux, AS), 1086 bytes"
    - there may be several sizes, of which the last one should be used, eg. "210. Haskell without MonomorphismRestriction, 10035 9977 bytes"

    There are only several answers with old format header: 1-5, 7, 12-17, 21. All of them have single size and don't have parens in language name,
    so they can be parsed with simple regexp.

    Algorithm: Find commas. If there are no commas parse it as old format. Otherwise parse it as new format.
    New format parsing: Let everything after last comma be `sizes`. Check if `sizes` ends with the word "bytes". If not, set size to 0.
    Take the word before "bytes" and convert it to number. Parse the rest of the header (before last comma) with regexp.
    function ParseHeader(header)
    var a = header.split(',');
    if(a.length > 1) // current format: Number "." Language "," Size+ "bytes"
    // filter(s=>s) removes empty strings from array (handle multiple consecutive spaces)
    var sizes = a[a.length-1].split(" ").filter(s=>s); // " 123 100 bytes " -> ["123", "100", "bytes"]
    var size;
    if(sizes.length < 2 || sizes[sizes.length-1] != "bytes") size = 0;
    else size = +sizes[sizes.length-2];

    a.splice(a.length-1,1); // remove last element
    var match = a.join(',').match(/(\d*)\.(.*)/);
    if (!match) return null;
    num: +match[1],
    language: match[2].trim(),
    size: size,
    else // old format: Number "." Language "(" Size "bytes" ")"
    var format = /(\d*)\.([^(]*)\((\d*)\s*bytes\)/;
    var match = header.match(format);
    if (!match) return null;
    num: +match[1],
    language: match[2].trim(),
    size: +match[3]

    // 1533246057 (number of seconds since UTC 00:00 1 Jan 1970) -> "Aug 2 '18"
    // other useful Date functions: toUTCString, getUTCDate, getUTCMonth, getUTCFullYear
    function FormatDate(n)
    var date = new Date(n*1000); // takes milliseconds
    var md = date.toLocaleDateString("en-US", {timeZone:"UTC", day:"numeric", month:"short"});
    var y = date.toLocaleDateString("en-US", {timeZone:"UTC", year:"2-digit"});
    return md + " '" + y;

    var processed = []; // processed answers, it's called `valid` in original snippet

    function ProcessAnswer(a)
    var body = a.body, header;

    // Extract header from answer body.
    // Try find <h1> header (markdown #). If not found try find <h2> (markdown ##).
    // Extracted header contains only text, all markup is stripped.
    // For 99 language markup is later readded to language name because markup is essential for it.
    var el = document.createElement('html'); // dummy element used for finding header
    el.innerHTML = body;
    var headers = el.getElementsByTagName('h1');
    if(headers.length != 0) header = headers[0].innerText;
    else {
    headers = el.getElementsByTagName('h2');
    if(headers.length != 0) header = headers[0].innerText;
    else { console.log(body); return; } // error: <h1> and <h2> not found

    var info = ParseHeader(header)
    if(!info) { console.log(body); return; } // error: unrecognised header format

    if(info.num == 99 && info.language == "99") info.language = "<i>99</i>";

    num: info.num,
    language: info.language,
    size: info.size,
    answer_link: a.share_link,
    user: a.owner.display_name,
    user_link:, // `undefined` if user was deleted
    creation_date: a.creation_date, // unix epoch (number of seconds since UTC 00:00 1 Jan 1970)

    function process()

    answers.forEach(ProcessAnswer); // answers -> processed

    processed.sort( (a,b)=>(a.num-b.num) ); // sort by answer number, ascending

    processed.forEach(function (a) {

    var date = FormatDate(a.creation_date);

    var user = a.user_link ? ('<a href="'+a.user_link+'">'+a.user+'</a>') : a.user; // redundant code, currently the only deleted user is ais523
    if(user == "user62131") user = '<a href="">ais523</a>';

    var style = (a.num == 194) ? "background: #ccf" : ""; // 194 is winner answer

    var row = "<tr style='{0}'><td>{1}</td> <td><a href='{2}'>{3}</a></td> <td>{4}</td> <td>{5}</td> <td>{6}</td></tr>"
    .format(style, a.num, a.answer_link, a.language, a.size, user, date);

    $('#answers').append( row );

    a {text-decoration:none}
    a:visited {color:#00e}

    table, td, th { border: 1px solid black; }
    td, th { padding-left: 5px; padding-right: 5px; white-space: nowrap; }
    tr:hover { background-color: #ff9; }
    td:first-child { text-align:center; } /* # */
    td:nth-child(4) { font-style:italic; } /* author */
    td:nth-child(5) { text-align:right; } /* date */

    p { margin: 8px 0px }
    .hidden { display: none } /* search hides rows */

    <script src=""></script>
    <span>Search: </span><input autofocus> &nbsp;<span id="results"></span>
    <table class="answer-list">
    <tr><th>#</th> <th>Language</th> <th>Size (bytes)</th> <th>Author</th> <th>Date</th></tr>
    <tbody id="answers">

    <div id="status">Loading answers...</div>

    For people who can see deleted posts: the Sandbox post was here.

    How should permalinks be updated? Should the newest answer contain permalinks of all the previous languages?

    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 I think what was meant was that should new answers contain try it links with the new code?

    In hindsight there could have been a requirement to check validity of answers before new answers can be posted, e.g. in meta regex golf.

    Is it ok if the language does not have an online interpreter, but has one on github (but has to be downloaded)?

    As PPCG rules require allowing as many languages to compete as reasonably possible, I don't think it can be fair to *require* there to be an online way to test the program (and the post as currently written doesn't), although you must of course give people some way to test. Perhaps you could try to persuade one of the online language hosts to add the language you're thinking of, though, to make things easier?

    @ais523 I have already written an online interpreter (based on the GH code) for haystack, but I will ask someone to add the language on TIO, thanks!

    I think we need a script that takes a hex dump of the code and automatically runs it in all the languages...

    Is it okay to exit with a non-zero error code that is not crashing, e.g. Befunge-98's `q` command?

    @Sp3000: Yes. Intentionally reporting failed execution is distinct from a crash.

    This is the Versatile integer printer posted as a different type of challenge. (Inspiration?) The final answer (currently) would score `0.0127`, only beaten by Sp3000's 30 language submission... :)

    @StewieGriffin I actually just added a snippet to my last answer that shows the scores for all the answers if they'd been submitted for that challenge

    This challenge is perfectly described by its tags: [polyglot] [answer-chaining].

    Can we use languages that were "created" (pushed to GitHub) barely a month after the challenge?

    @MDXF: Unfortunately no. PPCG rules are fairly frustrating for a challenge like this, but if you start violating them, you end up in a subjective minefield of what is and isn't legal.

    @ais523 that's disappointing. I was going to add ;# cause it's quite easy

    @cairdcoinheringaahing I really doubt it would be as easy as you think. There are quite a few `#`'s in the code, and it wouldn't be possible to just add random `;`'s.

    @MDXF it's probably the easiest language of all of them to add given that it was designed for polyglot Kolmogorov complexity challenges (# and ; are common comment symbols

    @StewieGriffin it is now under `0.003` :)

    @cairdcoinheringaahing Yeah, except there are already about 300 instances of `#` in the code.

    This challenge has been linked from the Wikipedia article on Polyglots.

    Are we going to award the accepted answer to anyone else than stasoid and potato44? Because they did most of the answers?

    @Michthan The accepted answer would have gone to the winner, which in this case is the second newest answer when 14 days have passed since the most recent answer. But because ais523 is no longer a member of PPCG no answer will get accepted as he isn't here to do so.

    For authors of similar challenges (in which bigger thing is built based on previous answers): please, don't prohibit a user from adding several answers in a row. This rule is harmful. It gave me a LOT of trouble, I had to wait for weeks, sometimes for months to add an answer. That was absolutely agonizing. This rule together with winning condition artificially creates competition for inherently collaborative challenge. Note that having winning condition is not obligatory - e.g. hello world challenge explicitly does not have one.

  • Note: If you see this first, you might want to sort by oldest

    17. Julia (128 bytes)

    #v`16 "<" 6/b0\ [email protected]#;n4"14""
    #>[email protected]|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.


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

    Where has everyone else's code gone though

    159 bytes to 128 bytes? Wow, that's some excellent golfing!

    Nice, 2^7 bytes

    I was working on a 99 version for 17, I got it within 2 bytes of the rules and then you come in with this huge improvement! I'm never going to get 99 into this aha.

    If you're going for golfing, the V section could be shortened to `HcL2`. Of course, I don't know if this would mess with the other languages or not.

    Wow... incredible! We're going to have to write up a new explanation for every language when all's said and done ;-)

    @mbomb007 ah fair enough, I had assumed it had to build on the others

    @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)"

  • 23. Hexagony, 186 bytes

    Sorry if this messes up plans...

    #v`16/"<"6/[email protected]"(::):::  (22)S#;n4"14"
    #>[email protected]|> ^*ttt*~++~~~%

    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.


    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.

    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.

    I would suggest Labyrinth next, but I want to do that one.

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

    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…)

    @MistahFiggins Cubix is also 2D (the source code is wrapped around the sides of a cube), and it uses the same implicit code layouting as Hexagony (it removes whitespace, pads the source to the smallest possible full cube, and then assigns the cells to their positions).

    In a sense this technically doesn't work in Befunge-93 for a spec-compliant interpreter, since the Befunge-93 spec has a fixed size playing field. Might be worth noting.

    @Sp3000 Ah, I had forgot about that. Most compilers ignore this, as far as I know, because it's pretty annoying. However, if you all think it's a big enough deal, I could try to edit it down to a size 8 triangle where most of the new characters are on the 2nd line. (It would probably take just as long to explain it, lol)

    I think it's fine if you mention your assumptions about the interpreter/compiler and note that it's technically not spec compliant. In a sense, it's just like having a slight variant of the language (cue language-is-defined-by-implementation meta comment).

  • 50. bash, 1024 bytes

    #16  "(}[email protected])" 3//v\D(@;'[af2.qc]GkGGZ'#)"14";n4
    #/*` "[!PPP(22)SP(>7 7*,;68*,@;'1,@ ␉␉␉␉ q
    # >[email protected]
    #=<xR+++++[D>+++++++L+++<-][pPLEASE,2<-#2DO,2SUB#1<-#52PLEASE,2SUB#2<-#32DOREADOUT,[email protected]/]>+.-- -. >][
    #Rx%>~~~+ +~*ttt*.x
    #[#[/v/v(/0l0v01k1kx0l0ix0jor0h0h1d111x0eU0bx0b0o1d0b0e0e00m1d0i0fx0g0n0n11x0o0n0cx0c0o0f0c0gx0g0f0h0j0j0i0001k10vx0v0l111111^_) 0046(8+9+9+9+9+=!)
    '\';echo 50;exit;';print((eval("1\x2f2")and(9)or(13))-(0and 4)^1<<(65)>>(62))or"'x"or'({({1})({1}[(0)])}{1}\{1})'#}#(prin 45)(bye)|/=1/24=x<[email protected][email protected]@@@=>+<@@@=>+<?#d>+.--./
    ###;console.log 39
    =begin //
    #define z sizeof'c'-1?"38":"37"
    main( )/*/
    #()`#`\'*/{puts(z );}/*'``
    <>{# }//
    disp 49#//
    #< >"3"O.
    =end #//
    #ss8␛dggi2␛ `|1|6$//''25 =#print(17)#>27.say#]#print(47)#]#echo 21#ss*///nd^_^_Z222999"26

    Want to learn more? Try the polygot chat!

    Try them online!

    As usual, I replaced literal tabs with and literal ESC characters with , due to limitations of Stack Exchange. You can get an easily copiable version of the program from the "input" box of the TIO link above.


    This program prints 50 in bash, 49 in Octave, 48 in Deadfish~, 47 in Lily, 46 in Cubix, 45 in PicoLisp, 44 in alphuck, 43 in reticular, 42 in evil, 41 in brainf***, 40 in Minimal-2D, 39 in CoffeeScript, 38 in C, 37 in C++, 36 in Labyrinth, 35 in INTERCAL, 34 in Rail, 33 in Incident, 32 in Whirl, 31 in Modular SNUSP, 30 in Whitespace, 29 in Trigger, 28 in Brain-Flak, 27 in Perl 6, 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng, 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 5, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in V/Vim, and 1 in Python 3.


    Most of the languages are tested by the test driver above. The usual four culprits need testing separately:

    • Incident was tested using its official interpreter, offline;

    • Deadfish~ was also tested using its official interpreter, offline;

    • Modular SNUSP was tested online here;

    • Reng was tested online here.


    I was looking at various leads for languages to add. One possibility was to find a language with # line comments that could plausibly be added to the "scripting language" line (which handles Perl, Python 2 and 3, and Ruby). It took me a while to think of an appropriate language that could be syntax-compatible with the ones already there, though.

    It turns out that the answer had been staring me in the face for ages. If you click the TIO link above, it'll open up the polyglot test driver, which is written in bash. So all this time, I had a tab saying "Bash — TIO Nexus". You'd have thought that'd be a hint, but apparently I missed it. As a bonus, bash is also a scripting language, so the term "scripting language line" is still appropriate.

    The bash program starts in the same place as the other scripting languages. However, there's a fairly simple way to split it away from them; in single-quoted strings, \ is an escape character in most languages, but not in bash. So we can hide bash code from the other languages via '\'…';, which is a degenerate statement (with no effect) in Perl, Python, and Ruby, but executed in bash. echo 50;exit is a fairly simple way to end the bash program. Well, almost.

    The biggest problem here is that bash will, upon running exit, continue parsing until the end of the current line (even though it doesn't execute the code in question), so we need to make sure there are no syntax errors on the rest of the line. We have a ' just after exit; that isn't (and cannot be) immediately matched. Later on on the line, '…' is used to hide some Brain-Flak code from the scripting languages, but that would unhide it from bash. As a result, we need to change what sort of string literal we're using to hide the code, going from single-quoted to double-quoted strings. or"'" does the trick without disturbing Perl, Python, or Ruby (as the left-hand argument is truthy in every case).

    We now have an unmatched double quote that extends onto a future line. It was fairly hard to close it without disturbing at least one other language; what we actually do is to change the way we hide code from bash from double quote back to an unmatched single quote in a Python/Ruby comment on the subsequent line, and finally close the single quote at the end of the line after that.

    Pyth and 05AB1E

    Messing around with double quotes also disturbs the languages that were using double-quoted strings to hide code, Pyth and 05AB1E. The main trick we use here is to ensure that every double quote we add has another double quote soon afterwards in order to expose as little code as possible. (This explains the extra double quote on the __DATA__ line, which isn't necessary for bash.) Pyth uses \ as an escape character; the main upshot of this is that it limited the scope I had for messing around with strings in the scripting languages, forcing me to use the rather convoluted method above (as I couldn't easily make use of the difference in \ behaviour between bash and everything else). In 05AB1E, ' acts as an escape character outside strings, and having it escape the leading " wouldn't do. So I ended up needing to place a useless padding character (defaulting to my usual x; it makes things easier to read!) inside the "'" constructs that are used to change between bash quoting styles.


    By far the hardest language to fix here. The problem is that the scripting line, with all its parentheses, was moved sideways, and thus the Prelude control flow (which cares a lot about the way in which parentheses are vertically aligned) was completely destroyed. I thus had to try to reconstruct something that works.

    Worse, the current first line (which I really didn't want to rewrite) places something of a hard limit on where the parentheses can appear. It starts off with a nonzero digit (two of them, in fact!), and is soon followed by an opening parenthesis. That's a loop in Prelude, and loops early on in the control flow in Prelude cause a number of different issues (mostly because they cause more code to run, rather than less). As such, I badly needed to open a 0-iteration loop on some other line in order to skip over that code. The main line for the C program is highly suitable, but we need to be very careful with where the matching closing bracket is; too far right and the unmatched bracket on the #R+ line will cause trouble, too far left and it won't comment out enough code. (Bear in mind that an opening parenthesis on one line can match a closing parenthesis o a different line.)

    Once that's done, we have just enough space to stick in an opening parenthesis on the Incident line, and we've finally got safely past the first few characters of the program. However, the difference in parenthesis placements ends up meaning that some of the Incident/Whirl code actually runs in Prelude, corrupting the stack. Instead of trying to prevent this, I moved some of Whirl's zeroes further to the right, allowing them to give us a working Prelude program again.

    One other small change was on the first line of the program; the final parenthesis of the line was in a position that was very hard to avoid. I added an extra c just after the Pyth code to shift it to the right. (Many languages are parsing that point of the program, so it took a surprising amount of trial and error to find a padding character that wouldn't break at least one language!)


    Prelude was hard enough by itself, but getting Prelude and Incident working at the same time was nightmarish. Prelude placed a lot of constraints on the code which prevented me freely moving things around, and thus made accidental token construction harder to golf out. For example, Prelude only really needs one 0 moved out to the right, but that caused 00 to become a failed token, breaking some of the tokens we wanted as part of the Incident program (because if two tokens overlap, they're both rejected, and the 00 was overlapping a token we wanted in addition to overlapping itself). I had to move both out to make a fourth copy and prevent it being even considered as a token.

    More subtle are the tokens ;' and ␠␠ (i.e. two space characters). The issue is that these both appear before the kG that is being used to jump to the start of the program, and thus will break Incident's control flow (in addition to breaking the program's centre point).

    Removing a copy of ␠␠ by breaking it up doesn't seem viable. Removing it via overlapping it might be possible (␠= is a promising potential overlap), but it's almost certainly less verbose to just add a fourth copy, which is what I did here.

    Meanwhile, we can use a different trick for ;'. Breaking it up isn't something I wanted to try, given that it's used in fairly spacing-sensitive situations. However, it's not that near the start of the program (despite appearing on the first line), so it's plausible that we could jump over it (thus causing it to not affect control flow) rather than needing it to not exist. I looked for a suitable token to use for the jump which wouldn't screw up any of the other languages. /v appears a little earlier on the first line, and doesn't break anything, and thus that's what I used.

    50 languages in 1 Kib of code

    It was pointed out by @MistahFiggins that my 1025-byte submission would be way neater if it were 1024 bytes (especially as the fiftieth language is a milestone in its own right). This required finding a byte of savings somewhere. In this case, I saved three bytes in the Deadfish~, at the costs of two extra bytes used to make Incident tokens line up correctly, and thus bringing the program down to 1024 bytes exactly.

    Previously, the formula that the Deadfish~ code used was (2²+2)²+10×1+2 = 48. The new formula is (3²-2)²-1, also producing 48. Surprisingly, it isn't that much shorter to write in Deadfish~, despite being considerably simpler.

    This also gives us a VIP score of .008192. Not only is this a new record, it's also a nicely round number in its own right (which is, obviously, a consequence of having nice round numbers as the inputs to the formula).

    Sorry for not having a TIO >_> (Sincerely, creator of Reng)

    @ConorO'Brien Ping Dennis? Also, ais523, you should try to golf a single byte off ;)

    You can cut the space in `puts(z )` if you swap `(` and `P` in line 2, thanks you the prelude leeway you've created. Bravo on this answer. #50in1k

    As it happens, I golfed off a different byte. Now it's at 1024 exactly I don't really want to change it :-) Perhaps a later answer can save some of the savings we have; there are likely a lot more (e.g. there's likely old Incident padding/detokenisation lying around that's no longer needed).

    @ais523 agreed. This answer was always meant to be 1024 bytes.

    Now all we need to add is malbolge.

    I was thinking about bash for ages but didn't think of this. Why doesn't `'\'` output an error in bash (`bash: \: command not found` or similar?)

    Ah, turns out the answer is that it DOES output an error...

    @Muzer: It's a warning, bash can keep running despite the command not existing. Warnings are generally considered irrelevant on PPCG.

    @ais523 It's definitely an error, it's just that bash ignores errors by default. I might try and fix it if I think of another language.

    (It's an error in that a command run by bash exits with an error state... not that it stops the script running. It's similar to PHP/etc. which also ignores errors where possible, IMHO)

  • 37. C++ (gcc), 776 bytes

    #  1"16" 2//v\(;@#/;n4"14"
    #/*`3 auaaZ<>16/"<"6/[email protected]")(22)S# ␉␉␉␉
    #yy␉;[email protected]
    # ␉
    print((eval("1\x2f2")and( 9 )or(13 ))-(0and 4)^1<<(65)>>(62))or'(\{(\{})(\{}[()])}\{}\{}\{})'#46(8+9+9+9+9+=!)#1|=/=1/24=x=9[<[email protected][email protected]@@@=>+<@@@=>+<?#>+.--.]/
    int main() /*/
    =end #//
    #0]#echo 21#/(\[FAC,1<-#2FAC,1SUB#1<-#52FAC,1SUB#2<-#32FACLEGEREEX,1PLEASEGIVEUPPLEASE) ap
    #0␛dggi2␛`␉|1|6$//''25 >>>>>#>27.say# =#print(17)#^_^_7LEintndus({})!<>+]/*///Z222999/[email protected]"26

    is a literal tab, a literal ESC character; Stack Exchange would mangle the program otherwise. I recommend copying the program from the "input" box of the TIO link below, if you want to work on it.

    Try them online!


    This program prints 37 in C++, 36 in Labyrinth, 35 in INTERCAL, 34 in Rail, 33 in Incident, 32 in Whirl, 31 in Modular SNUSP, 30 in Whitespace, 29 in Trigger, 28 in Brain-Flak, 27 in Perl 6, 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng, 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 5, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in V/Vim, and 1 in Python 3.


    Most of the languages are tested by the test driver shown above. You can test Reng here and Modular SNUSP here; they output 19 and 31 respectively, as required.

    I added another format to the test driver output that escapes double quotes as well as make line feed replacements. This is so I can feed the single line string to a c(gcc) program I wrapped around the function created by @feersum here. Hopefully others can make use of it as is.

    Here's the Incident token program. Ideally I'd like to deliminate the tokens since they are a bit hard to read, indicate the "center" token, and include it in the test driver. But I don't really know how to do anything other than make various programs print sequential integers, so this is as far as I've gotten.

    I've attempted to solve the obvious Incident problems, like tokens after the beginning and end jump tokens and anything that looked extraneous, but I haven't balanced the tokens to put 0o at the center. I'm not really sure what the logic is exactly to determine the center. I'm hoping @ais523 will help there. This string near the end 7LEintndus({})!<>+ would all be tokens if not for this 4th inclusion in the code. These can all be removed (and replaced with a . for Hexagony alignment) in order to adjust the center token.

    I'm going to be updating this post off and on over the next day or two to walk through the code, (assuming Incident can be verified/fixed without going over the byte count). But it's super late now, and I mostly wanted to get this out there before I had to solve another Labyrinth like problem. :P


    How the C++ code works.

    I think most people are familiar enough with C++, so I won’t go into too much detail. Block comments come in the form of /* comment */. Line comments come in the form of //comment. The actual code utilized by C++ to produce the answer is int main() {std::cout<<37;}. And the library that’s used to interface with STDOUT is referenced by this statement #include<iostream>.

    /*Comments Abuse*/

    For me, the story of C++ goes back to my Brain-Flak answer.

    After finally finding #28, I set out to study some other polyglots posted in PPCG and all that studying led me to a few easy answers (most of these are still available to be found if anyone else is so inclined). But more importantly, I came to a conclusion about polyglots in general: large polyglots tend to fall into one of two broad categories: # comment abuse or /* comment abuse.

    This is not a fact or restriction in anyway, but of a personal mental framework that guided my next several answers.

    From here I reasoned that if this was to become the world’s largest polyglot, which I presume it to be currently, it would be best if it could leverage comment abuse from both comment families. So I set out to find a way incorporate a /* comment language and pushed towards the C family due mostly to a personal familiarity.

    C++ Initial Test

    My initial thought process for this was to use C# mostly because of my familiarity and the first hurdle for C# was getting the polyglot into a state where it could accept a line that didn’t start with # without otherwise being treated as code by the scripting languages. The Rail answer, along with several byte inflating answers that lead up to it, solved this piece.

    Next came the problem of how to initiate the first /* comment block. I knew the line would have to start the line with a # to remain invisible to Perl, Ruby and Python, but whatever came before the /* would be read by C#. I attempted a C# #region tag at first, but that turned out to be too ridged for the 2D languages. Enter C++.

    C++ has several preprocessor directives that all start with #, which give a lot of options for the 2D languages to traverse. But it turned out that all of them were incompatible with at least one language, and being in a C++ exposed code space, I had limited workarounds. Out of frustration and desperation, I stumbled into the fact that C++ would simply accept just a single # before the comment block. Okay, whatever, that’s workable. So I moved forward with the presumption that #/* could work as the first three characters in the polyglot.

    The second piece of basic verification was to ensure that the actual print statement could live happily with the other codes. I knew from the Brain-Flak answer that Japt didn’t like un-escaped {’s and that was needed for C++ to say int main() {std::cout<<37;} and C++ wouldn’t allow Japt’s escape character in the middle of its code. This time I was lucky enough to find that if I dropped out of Japt’s literal string just for this statement, Japt would still happily produce the same result.

    Meanwhile, Brain-Flak didn’t like the {} either, but I was again lucky to find that C++ was ok with a # between its int main() and {std::cout<<37;} statements, allowing the curly braces to be commented out of Brain-Flak’s perspective.

    So, with the main problems of C++ proven to be theoretically solvable, I began the arduous process of resolving all the errors I’d introduced.

    2D Landscape

    The hardest part of this answer was by far the reconfiguration of the top two lines of the polyglot. And the most significant problem was the *. Underload will not allow a * prior to a (. It considers this as math operation on an empty stack, which it feels is an error. So the polyglot required a ( prior to the /* but C++ couldn’t allow this. So the solution was to us a C++ line comment // on the first line to hide a ( and then start the second line with a #/*.

    Next, Befunge really didn’t like the idea of a / without something being divided but after studying the existing Begunge answer of 16/"<"6/[email protected] I stumbled on the idea of a number and a string smashed together ahead of the //. It worked and I have no idea why C++ is ok with this but it accepts # 1"16" 2 as it’s opening statement. I’m not going to question it, but I do know that the spaces are required for it to work.

    Line One

    Japt turned out to be rather space sensitive and didn’t really want to enter into its backtick based string on the top line, so it and Pip’s backtick got moved to the second line, forcing a lot of linguistic gymnastics on line 1.

    • Pip didn’t like most of line 1, so a second space was placed after the first #to indicate a comment.

    • The ( for Underload had to be escaped out of Japt with a preceding \.

    • # is a jump terminator in Turtlèd so it was required, but Pyth considers this a error terminating loop, so Pyth needed a divide by null / after the #

    • I’m not sure what the @ in the first line is doing anymore, but Pyth and Japt seem to like it’s presence better than not, although @ is not a meaningful character according to Pyth’s documentation.

    • And it looks like the first ; can be removed at this point without consequence, so I’m not sure what was being solved there anymore, although I suspect it was Pyth related. But it looks like future solutions can save a byte by omitting that one.

    • <>< and Turtlèd both basically work the same as before with <>< reflecting on the first # and wrapping to the end of line one. And Turtlèd jumps with # like I mentioned and ends with the "14" string which it prints.

    2D routing

    With these issues resolved, the next phase was routing the 2D languages. Previously the initial v was ignored by the Befunges due to the preceding #, but sent Haystack and Minkolang down. Now, the initial space attempts to send Minkolang along the 3rd dimension, which its documentation refers to as the time dimension.

    Quick aside on Minolang’s 3rd dimension: to me it’s something of a misnomer to call this a time dimension it really seems more spacial than temporal to me. I didn’t really get it until I found this link that illustrates the concept, and it seems more like the multiple layers of a 3D chess board. My belief is that this is how 3D languages generally operate. But as this was a new concept to me, I thought I’d throw this info out for others.

    So Minkolang’s multiple layers are delimited by lines ending in $$$ which I threw onto the end of the Rail code here: #-3o4o#$$$. Now, Minkolang hits the space and falls to first > in <>3N.<> ␉// and proceeds to the right outputting 3. #>couldn’t be allowed to start this line because it would attempt to terminate a Perl6 comment block, so < is used instead of # to balance for SMBF and Brain-Flak. However, this is a Brain-Flak stack swap procedure, so a second set of <> is used after Minkolang Terminates in order to swap back to Brain-Flak’s correct answer.

    Labrynth similarly bumps up against the space but it causes Labrynth to moves down in column 1. It then turns down line 2 where it travels down to the 3 hits another wall, causing it to turn south again and hit a ; which causes the 3 to get popped. Then the program continues to the right where 36 gets stored and printed, before finally finding a @ exit. This path is longer than it needs to be, but I found that Prelude would output a nul byte before it’s normal 20 output if the ! was any further to the left than it is now, regardless of the line it appears. So I made it more correct, because I had the space to do so.

    Next, Haystack’s routing got changed because / now comes prior to v on line 1 and reflects its path up like Reng. Fortunately, Reng cohabitates rather peacefully. The one hitch was that Haystack’s needle | was a reflector in Reng, so a Reng uses a Befunge like jump (#) over the needle to conclude Reng correctly.

    The Befunges continue along line 1 until the v and get directed down and then to the right on the second line to conclude with the same code used before. My sense is that this piece can be golfed down a bit now that fewer languages are attempting to meaningfully traverse the code, but I didn’t need any more walls to bang my head against, so I left it as is.

    Finally, Cardinal’s starting point is % which had no particular need to be lumped in to the already dense top two lines. So I moved it down to Python’s string. Its multiple code paths are also now bounded by x’s, which ends the movement of its pointer.

    Line 2 &3

    The only significant change here is that all of the : got golfed out for one reason or another. Maybe Prelude’s ( needs or maybe it was simple byte count problems – probably both. The other thing is that trigger’s jump code got moved back and rebranded as auaaZ. I had space to fill to meet Befunge’s code path and this seemed best. Also the < following this piece is to balance SMBF’s following >. Finially, the lone near the end of the second line are to maintain 05AB1E’s string. Also, yy on line 3 are just filler characters for Labyrinth.

    The Big String Esolangs

    With the top two lines resolved, it was time to start digging into the fuller-parsing esolangs, and Pip turned out to have a problem. If you remember we dealt with the curly braces in {std::cout<<37;} by dropping out of the Japt string to let Japt treat this as code. Well, Pip is using the same string syntax and didn’t like this line as code and Pip has very similar string declaration options as Japt. Both use a single ' to declare a one character string, both use the same escape declaration of \ and both will accept " as string identifiers. So it was difficult to make Pip believe this was a string without making Japt believe the same.

    It turned out that Japt did have one exploitable difference though - # takes the ascii value of the next character. So, #"` will terminate the Japt/pip string, then tell Japt to take the asci value of ", while telling Pip to start a new string. The " probably could have been a backtick instead, and probably would have been better, but my line of thinking was to use a different string identifier on the inside as another point of string manipulation. So here’s another place where you could save a few bytes down the road.

    Next, I had to initiate the Japt string after the curly braces while allowing Pip to remain in a string. I did this with '"` that's a single quote, double quote, and a backtick. For Japt the ' is not in a string and is therefore an indicator to take the next character as a single char string. Pip sees the ' as part of the string and terminates its string with the ". And finally, ` is indicates to both Pip and Japt that another string is beginning which continues throughout the polyglot until the last line where both languages complete happily.

    Now, both Japt and Pip worked at this point, but 05AB1E failed because of the use of " caused some error inducing code exposure. Fortunately this one was easy enough to solve by putting another set of " around the whole thing, leaving the set of string manipulations as "`#"\\'*/{std::cout<<37;}/*'"`".

    Finally, with the line now looking like this,int main() #/*"`#"\'*/{std::cout<<37;}/*'"`" which Underload had a problem with. The consecutive *’s, were another syntax error so I threw a () in the middle of the *’s to appease it.

    The Fragile Esolangs

    The big hurdle now was White Space. I won’t go into a ton of detail here because most of the Whitespace solution is built into the explanations already given, and I just glossed over the instances where whitespace forced a few decisions. I’m looking at you Labyrinth. The big change though, is that the actual code to output Whitespace’s answer is on line 2-4 instead of 1-3. This is largely due to Japt’s code exposure in line 1.

    Thutu originally had problems with what had been this line: int main() #/*()"`#"\'*/{std::cout<<37;}/*'"`". So, I threw in a linefeed just before the first # to hide all the problems behind a comment indicator and then spammed out a bunch of trailing /’s everywhere else that was code exposed.

    At this point I aligned Hexagony and found new problem. The code at the very beginning, which started life as # 1"16" 1 made the + in /[email protected] no longer clear the stack. So, I just removed the + is and found it now output 123. This was easy enough to fix by changing the opening gambit to # 1"16" 2 and golfing the Hexagony piece down to /[email protected].

    Whirl had some changes, but it was mostly a matter of making sure the right number of leading 1s appeared before the Whirl-Incident line. Incident though had one token that was particularly difficult. I had exactly 3 copies of /* and */.

    I initially wanted to just throw *//* any old place in the code to create a 4th copy of each, but Underload saw consecutive *’s again, which was a no go. Ultimately I threw a / on the end of this line int main() /* to make it end in /*/, thinking that I’d make the tokens overlap, but I only succeeded in creating 4 copies of one of the two tokens. Right, right. That’s how that works. Oh well, I’ll just throw a similar / in the final */ to make a 4th there. After this, I replaced a bunch of hexagony no-ops with a 4th copy of several incident tokens in this string on the final line 7LEintndus({})!<>+.


    Ok, that's all the detail I have for this massive refactor. I promise not to have so much to write about next time. I actually have no idea if C++ is a good or bad choice for this polyglot, but my sense it opens some options. Hopefully this leads to good things.

    Happy coding.

    Looks like `g++` requires a `.cpp`, so I added that to the file extension specific section. Then just had to use `` to handle it. I'll edit it in.

    If I'm following the Incident correctly, looks like another token that has all 3 occurrences after the second `0o` would fix it. Currently, `#xx`, `#0`, and `p` appear twice. Can one of the `a`'s at the end of the 3rd to last line be replaced with a `p`?

    @SnoringFrog Yeah, that looks do-able. I'll update the post.

    I want to add symbolic brainfuck to this as it's an easy addition, but unicode characters crash python2 - _ -

    @SnoringFrog I feel the same way about emoji

    "Middle token" in Incident is defined as the token which has the same number of tokens before it and after it (or if there's an even number of tokens, one more after than before, as an exact tie is impossible then). C is one of the languages I was considering adding; I'm not sure what the purpose of a null directive (`#` on a line by itself) is meant to be, but they're defined in the standard, so we can expect them to work.

    Also, `**` isn't a syntax error in Underload; it just consumes a lot of stack, which I assume wasn't available at the time (likely because you golfed out the colons). You can top up the stack with parenthesized groups or colons before or between them, or sometimes hide the code from Underload by parenthesizing it.

    @ais523 Aweome. Thanks for the clarifications.

    @ais523 In the very early days of C, to save time in cases where it was unnecessary, the preprocessor wasn't run unless the first line started with a #. But if you didn't want your first line to be a preprocessor statement, you would therefore need a way of having the first line start with a # without having it actually do anything, so you had the null directive. I strongly suspect backwards compatibility with code that used this was the rationale for its inclusion in the standard.

    Anyone who works Java into this earns *every internet point*

    What is PPGC *?*

    @user202729 Programing Puzzles & Code Golf, meaning this stack exchange. I saw the acronym used a few places, but I suppose it's not terribly common. :/

    @Chance PPGC is not "terribly common". PPCG is.

    @user202729 lol. fixed.

  • 3. Minkolang v0.15 (26 bytes)


    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!


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


    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

    “move through time” wat?

    @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

    @mbomb007 What exactly are you referring to?

    @mbomb007 4th submission (><>) already posted :)

    @KritixiLithos I posted ><> without even reading you're suggestion. It's such a good choice for this sort of thing

    @BlueEyedBeast 2d languages *are* a good addition to polyglots

    Added Befunge in addition to Minkolang :-)

    @JHM Now we have 2 *more* 2d languages added to Befunge :)

    @TùxCräftîñg I don't think I can do that

    @wat Hm this took me way too long to understand

  • 5. Python 2 (35 bytes)

    print('1'if 1/2else'5')

    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.

    I can confirm it works in Minkolang

    `print('1'if 1/2else'5')` breaks on my system without a space between 1/2 and else

    Well, it works with both versions on TIO.

  • 4. ><> (29 bytes)


    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.

  • 28. Brain-Flak, 280 bytes

    #v`16/"<"6/[email protected]"(::):::   (22)S#;n4"14"
    #>[email protected]|> ^*ttt*~++~~~%
    print((eval("1\x2f2")and (9) or (13))-(0and 4)^(1)<<(65)>>62)or'(\{(\{})(\{}\/^[email protected][()])}\{})(\{}\{})'#@46(8+9+9+9+9+=!)=#print(17)#]#echo 21#|/=1/24=x=90/
    #8␛dggi2␛` |1|6$//''25 #>say 27#"26

    ␛ represents a literal ESC character, as usual.

    This program prints 28 in Brain-Flak, 27 in Perl 6, 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (tested 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 5, 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

    First off, I want to say what a privilege it is to be able to contribute to this challenge. I only heard of code golf a few weeks ago and I have been absolutely hooked ever since. The first thing I did when I found this challenge was try to run the code as is in various languages just to see if I could find anything I could work with. This was back when we were on like #6. I honestly thought this challenge was bonkers impossible, but here we are (#28 Wow!). What I found at the time was that Brain-Flak output the value 2. So I set out to learn it.

    Brain-Flak turned out to be pretty great for this kind of challenge because it's fairly easy to learn and it ignores pretty much any characters except (){}[]<>. # also happens to comment anything after it on the same line, so the only part of the last submission that was ever considered for Brain-Flak was print((eval("1\x2f2")and 9 or 13)-(0and 4)^1<<65>>62) which then paired down to ((())()<<>>). So then the plan became adding superfluous parenthesis to what I've come to think of as the python code.

    I modified the python bits to parse in Brain-Flak to ((() () ())()()<<()>>) which equates to 2 stacks the first being 5 and the second being 3. After that I'm squaring the 5 with ({({})({}[()])}{}) and adding the result to 3 with ({}{}). This squaring and adding is going on in a string from a Python perspective. I can't claim to understand Python's reasoning here, but I am fairly confident that this string isn't otherwise being evaluated by other languages in a meaningful way, with only a couple exceptions.

    Japt, it turns out, interprets curly braces within a string as containing code, but these were easy enough to escape out with \ before each { in this string. But this bloated up the byte count. Such is life.

    Prelude was pretty forgiving with all of my parentheses. An earlier comment pointed out that Prelude would have fits with vertically aligned Parentheses and I happened to only create one. Sweet! The ( in the top line lined up with the and (9 in the big line. So I had to add an additional space before the ( in the top line. My assumption here is that the double space was a comment indicator for something, so adding an additional space seemed trivial, and it worked. I should point out that I tried adding a additional spaces in the (9) instead, but Cardinal didn't cooperate.

    05AB1E didn't like my first attempt at the Python string being encapsulated in double quotes, but everyone seemed agreeable to using single quotes. Not a big deal there.

    Hexagony was the only language left at this point, and I was obviously way past the next hex size threshold, so it was time to get dirty. The /^[email protected] is the Hexagony code and I'm super excited about it, because I think it'll make future additions much easier. This little piece can basically be moved anywhere in the python string without busting any code. This is the full string just so we're all on the same page '(\{(\{})(\{}\/^[email protected][()])}\{})(\{}\{})'. The / here sets the path of Hexagony from SE ->NW to W-> E down this string, which we have a lot of leeway with. (The preceding \ is to escape / for thutu BTW). My idea here is if you make changes, odds are that you'll end up going through this string at some point and you can slide the Hexagony piece around within the string to catch the code path and send it to the proper conclusion. Just take care not to come between Japt's \ and the {. If you have trouble with this, the @ to the right of the string is just left over from another Hexagony solution, and can be removed without consequence to the other languages. And of course if you happen to catch Hexagony's code path going the opposite direction, you can of course use @!32^\ instead of /^[email protected]. Also, you may notice that my solution removed the ===2 from the code to keep things under the byte limit. Someone mentioned in here that this was for Hexagony's alignment and I didn't need it anymore.

    Finally, here is a little piece of code I found while exploring codegolf that converts a line of text into a Hexagony readable hexagon so you can debug. I'm sure plenty of people know about this, but I hadn't seen it posted here, so it might help someone else too. Fair warning, you have to alter the input to remove the back ticks and carriage returns as well as swap the literal escape for something that takes up normal amount of space to get the code to line things up in a pretty Hexagon.

    P.S. While I was writing this out, I realized I had a mistake. I had believed I was clearing Hexagony's memory edge for with the ^, but apparently I can replace it with a no-op to no consequence. That ^ should probably be a + if you try to manipulate this section. I was apparently passing through a + prior to this, but future polyglotters may not be so lucky.

    Good Luck!

    I was waiting for the rundown and explanation before voting, but the rundown looks good, so I'll vote while waiting for the explanation :-). I assume that all the extra backslashes are to avoid a syntax error in Thutu? Also, interesting approach for where you added your code, which I'm guessing has something to do with Hexagony. It'll be nice to see the full explanation. (Also, welcome to PPCG!)

    And now I see the explanation; I enjoyed reading it. The "Python code" is actually used by several scripting languages (Python, Perl 5, Ruby), but they all interpret `and` and `or` the same way, so your method of commenting the code out in the scripting languages but not Brain-Flak happens to work in all of them.

    Thanks @ais523. You mentioned the placement of my code. So, I knew I had to place the brain-flak operators somewhere that was visible to the _scripting_ languages and my initial, incorrect assumption was that it would be easiest on a new line. This didn't work for Retina and I didn't want to deal with both it and the 2D language problems I'd create trying to fix Retina, if possible. I was lucky to stumble into the current placement.

    Fantastic answer, and a very thorough explanation! I'm really happy to hear that you enjoy brain-flak. :D

  • 2. V (11 bytes)


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

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

    It's a very straightforward answer.


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

    Of course, in python


    prints '1', and


    is a comment.

    Is this V or Vim? The interpreter you linked to is technically "V".

    @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?

    Not really, just edit the title in the answers.

    Does V have a way to exit Insert Mode?

    @mbomb007 A literal ESC character will do it (which is why I had to use one in my submission).

    I meant is there a printable character that can do it? Otherwise, is there another way to output in Vim that won't require an ESC afterwards?

    Vim restricts the use of all non-ascii characters... Ah well, no Aheui I guess... :'(

    Note for those testing this out: You need to make sure you don't have a cliipboard carried over from the previous Vim session.

    I don't have Vim installed but I have Vi in which the `i` in `print` triggers insert mode - according to the man pages `r` is replace a character in both languages, why does Vim ignore that first `i` but not Vi? Thanks!

    @JungHwanMin turns out that wasn't the case

  • 38. C, 804 bytes

    #  1"16" 3//v\(@#/;n4"14"
    #/*`3 auaaZ<>16/"<"6/[email protected]")(22)S# ␉␉␉␉
    #yy␉;[email protected]
    # ␉
    print((eval("1\x2f2")and( 9 )or(13 ))-(0and 4)^1<<(65)>>(62))or'(\{(\{})(\{}[()])}\{}\{}\{})'#46(8+9+9+9+9+=!)#1|=/=1/24=x=9[<[email protected][email protected]@@@=>+<@@@=>+<?#>+.--.]/
    #define␉z sizeof 'c'-1?"38":"37"
    int main() /*/
    =end #//
    #0]#echo 21#/(\[FAC,1<-#2FAC,1SUB#1<-#52FAC,1SUB#2<-#32FACLEGEREEX,1PLEASEGIVEUPPLEASE) ap
    #0␛dggi2␛`␉|1|6$//''25 >>>#>27.say# =#print(17)#^_^_7LEintndus({})!<>+]/*///Z222999/([email protected])"26

    is a literal tab, a literal ESC character; Stack Exchange would mangle the program otherwise. I recommend copying the program from the "input" box of the TIO link below, if you want to work on it.

    Try them online!


    This program prints 38 in C, 37 in C++, 36 in Labyrinth, 35 in INTERCAL, 34 in Rail, 33 in Incident, 32 in Whirl, 31 in Modular SNUSP, 30 in Whitespace, 29 in Trigger, 28 in Brain-Flak, 27 in Perl 6, 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng, 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 5, 8 in Retina, 7 in Japt, 6 in SMBF, 5 in Python 2, 4 in ><>, 3 in Minkolang, 2 in V/Vim, and 1 in Python 3.


    Most of the languages are tested by the test driver shown above. You can test Reng here and Modular SNUSP here; they output 19 and 31 respectively, as required.

    Here is my slightly tweaked version of the Incident tokeniser, designed to be a bit less golfed but a bit more useful.


    I've always loved making little polyglots but never one as big as this; I thought I should probably give it a go!

    After @Chance's wonderful C++ answer, C seemed the next logical choice, and given (compared to some previous answers) the relative ease of adding it, I decided to go for it when I had the chance!

    I used a very well-known trick to tell the difference between C and C++; the sizeof a character constant is 1 byte in C++ but the sizeof an int (guaranteed to be at least 16 bits) in C. This code should be very portable (except maybe for systems that use bytes with enough bits to fit an int) unless I've made a stupid mistake.

    I firstly tried to do a printf with everything inline, but the multiple brackets seemed to be causing issues for Japt, so I made the line simpler, which appeared to fix it.

    Next, Cardinal didn't like it, I guessed because of the % in the printf, so I had to solve that one by switching to manipulating strings.

    My next attempt, trying to assign a string then change the second byte contingent on the C behaviour, ended up far too long and would have pushed Hexagony onto the next size; I wanted to avoid redoing that by keeping it within the extra characters I had to play with! I needed every byte I could get for this, so I implemented the byte-saving changes suggested by @Chance.

    So I golfed that C code down a bit and came up with puts(sizeof'c'-1?"38":"37"); which almost worked, except that Underload was segfaulting, presumably because of the complex expression in the brackets.

    Even after removing the extra >> that used to be required to match the << in Perl6, I couldn't get a concise enough way to split out the more complex part of it into a char array assignment. So I ended up looking at using the preprocessor instead.

    After a lot of trial and error I found a solution that Retina seemed to like. Prelude which was causing me problems on-and-off all the way through, ended up fixing itself before I got round to looking at why it was breaking (I guess either the brackets or the ! I had in the ternary at one stage, looking at previous answers).

    All the while I was patching up the whitespace to get something that Whitespace would like; I found that to be rather easy. Specifically, tab space space space was a very useful combination (the instruction to add the top two items on the stack), since it meant I could add whitespace to lines with no other whitespace without having everything go out of sync (I'm guessing its position in the program means it never actually gets executed so I'm not worried about stack underflows here).

    I've now tested Incident, and it works! Many thanks to @Chance and @LliwTelracs, which I've just realised is NOT a Welsh name, for helping me get to grips with it. See this syntax highlighting. I have removed the ; token that was appearing before the #yy token. I did this by simply adding an extra ; after the gets statement (my previous attempt involved replacing s (which now appears much more in the C program than it did in the previous one) in the "detokenising" string with a ;, but it turned out I was actually a character short for Hexagony (thanks @Chance), so after attempts to add an extra character to this last line failed, I just changed it back and added the extra semicolon elsewhere).

    I have also tweaked the whitespace a little to change some other tokens to make some attempt at centring, to re-tokenise Tab Linefeed (by moving the tab at the end of the #include line to in the middle, thus making three tokens), and to de-tokenise the triple-space token by moving one space in the define line.

    Finally, a day after initial submission, I decided to get to the bottom of the scary preprocessor warning that gcc produced (and which made Clang fail). I determined that the reason the first line worked at all is because it's the output from the preprocessor that provides debug info like original filenames and line numberings. They didn't like the first "2" on the first line, because this meant "returning from an included file into the given file", and obviously that's impossible given there haven't been any included files. After changing it to a "1" (start normal header) made a few too many languages choke, I changed it to a "3" (start internal component header), which broke only Hexagony, since it was now relying on the 2. So at the start of the Hexagony code I added an open bracket ( to decrement the 3 to a 2, then a close bracket ) after the end (@) of the hexagony code to satisfy Retina, Prelude and Underload which all expected matching brackets. Re-testing Reng and Modular SNUSP produced no issues, and the Incident tokens looked right, so I had now fixed it! I've tested it on a variety of exotic architectures and it appears to work. I know it's not important for a code golf, and I won't mind if future submitters have to break this again to keep within a byte count or whatever (or if anyone's already started based on this solution and doesn't want to change theirs too much), but there is one good reason I've done this - TIO's Objective-C compiler only supports Clang, so this'll be very useful if anyone wants to add that!

    Bear in mind I've never used most of these languages, I hope my success encourages more newcomers to give this a try!

    @LliwTelracs Huh, the C program linked by Chance in his answer had a different output for the list of tokens: ;#yy;#yy#yy0l0m1k1k0l0i0j0h0h1d0e0b0b0o1d0b0e0e1d0i0f0g0n0n0o0n0c0c0o0f0c0g0g0f0h0j0j0i1k0m0m0l^_()z z()()z; ^_^_

    The error was that I was copy pasting the value to my program so it couldn't recognize the tabs or escapes

    @LliwTelracs Just trying to figure out the tokenisation myself, it looks like I've now got a semicolon appearing three times. I could add an extra one except that I don't think I can spare the byte as that'll misalign Hexagony. Hmm...

    @LliwTelracs I've now figured out how to get rid of that semicolon token without using an extra byte (I somehow missed the bit about the detokenising string at the bottom which I could modify; very useful!). I don't know if the centre token is right, but I hope so!

    the Stack overflow treatment of spaces made me take a while looking for why my code was getting 3 spaces in a row as a token but the C program was not.

    @muzer Ignoring the incident jump tokens and the actual incident code, my solution was balanced with one token on the left `␉␊` and 8 on the right `p()␉␊␉␊()()pp `. The token's here being `␉␊`, `p`, and `()`. Yours has none on the left and 9 on the right: `()z␠␠␠z()()z␠␠␠␠␠␠` with the tokens being `()`, `z`, and `␠␠␠`. I believe as long as the number of right tokens minus left tokens = 7 then everything is balanced. I'd try eliminating the triple space as a token then create a token weighted once on the left and twice on the right. Maybe there's one available in the detokenizing string?

    @Chance Thanks for that! I just made a less golfed more useful version of the C program, and with its help I think I've managed to sort out Incident in this. I will try to test it when I get home ( is blocked on the train and esolangs wiki appears to be down).

    I noticed one more thing. Hexagony is outputting a couple trailing nul bytes because it's alignment is one space left of where it wants to be. Throwing in another character anywhere before `/[email protected]` will fix it.

    @Chance Oops! Cheers, dunno how I missed that. Trying to add an extra character to the detokenising string in last line seems to make Prelude go insane, so I'm replacing the semicolon back with an s, and adding an extra semicolon after the "gets" statement.

    Incident works!

    @Chance I've just been looking at how that first line is valid in the C Preprocessor, it looks like it's the output from the Preprocessor used for debug info etc. It means "now returning (2) to file with name "16" line 1". I think it's the 2 that makes Clang choke (and gcc warn) since it never went into any files in the first place, so there's nothing to return from. When I get the chance I might experiment with changing it to something else to make it compile in Clang too. See

    @Muzer Cool! Thanks. I love how much out of the norm stuff I'm learning from this project.

    @Chance Just fixed compilation in Clang. I discovered a potential future use for this is Objective-C, since TIO only supports Clang for that language.

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM