308
\$\begingroup\$

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

  • If some interpreter gets updated and the program no longer works in the newer version then new answers can either stick to the old version or fix the program to work in the new version.

  • 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 https://codegolf.stackexchange.com/questions/55422/hello-world // It was tested only in Google Chrome // https://stackoverflow.com/a/4673436 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 "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } var answers = [], answer_page = 1; function getAnswers() { jQuery.ajax({ 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](http://api.jquery.com/jquery.ajax/) states that `error` handler is not called for cross-domain JSONP requests, // but it works here, probably because api.stackexchange.com and codegolf.stackexchange.com are on the same domain. error: function (a,b,c) { $('#status').text( "Failed to load answers: " + b + " " + c ); console.log( b + " " + c ); }, }); } getAnswers(); // https://stackoverflow.com/questions/6290442/html-input-type-text-onchange-event-not-working/39834997#39834997 // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event 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 = ""; num_results++; } } else { 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; return{ 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; return{ 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>"; processed.push({ num: info.num, language: info.language, size: info.size, answer_link: a.share_link, user: a.owner.display_name, user_link: a.owner.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() { $('#status').remove(); 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="https://chat.stackexchange.com/users/246227/ais523">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="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p> <span>Search: </span><input autofocus> &nbsp;<span id="results"></span> </p> <table class="answer-list"> <thead> <tr><th>#</th> <th>Language</th> <th>Size (bytes)</th> <th>Author</th> <th>Date</th></tr> </thead> <tbody id="answers"> </tbody> </table> <div id="status">Loading answers...</div>

\$\endgroup\$
28
  • 4
    \$\begingroup\$ For people who can see deleted posts: the Sandbox post was here. \$\endgroup\$ Commented Dec 6, 2016 at 19:00
  • 6
    \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 6, 2016 at 19:44
  • 4
    \$\begingroup\$ @ais523 I think what was meant was that should new answers contain try it links with the new code? \$\endgroup\$ Commented Dec 6, 2016 at 19:45
  • 7
    \$\begingroup\$ I think we need a script that takes a hex dump of the code and automatically runs it in all the languages... \$\endgroup\$ Commented Dec 7, 2016 at 20:05
  • 5
    \$\begingroup\$ 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... :) \$\endgroup\$ Commented Dec 17, 2016 at 12:11

451 Answers 451

1
2 3 4 5
16
19
\$\begingroup\$

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

\$\endgroup\$
3
  • \$\begingroup\$ Would ><> be a good choice for the 2nd language (so that we start 2d space)? \$\endgroup\$ Commented Dec 6, 2016 at 19:07
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 6, 2016 at 19:09
  • 2
    \$\begingroup\$ @DJMcMayhem Each answer must be no more than 20% or 20 bytes (whichever is larger) longer \$\endgroup\$ Commented Dec 6, 2016 at 19:10
26
\$\begingroup\$

2. V (11 bytes)

print(1)#i2 

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.

print(1)# 

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

print(1) 

prints '1', and

#i2 

is a comment.

\$\endgroup\$
10
  • 3
    \$\begingroup\$ Is this V or Vim? The interpreter you linked to is technically "V". \$\endgroup\$ Commented Dec 6, 2016 at 19:22
  • 2
    \$\begingroup\$ Not really, just edit the title in the answers. \$\endgroup\$ Commented Dec 6, 2016 at 20:12
  • 1
    \$\begingroup\$ @mbomb007 A literal ESC character will do it (which is why I had to use one in my submission). \$\endgroup\$ Commented Dec 7, 2016 at 0:05
  • 2
    \$\begingroup\$ Note for those testing this out: You need to make sure you don't have a cliipboard carried over from the previous Vim session. \$\endgroup\$ Commented Dec 9, 2016 at 7:14
  • 1
    \$\begingroup\$ 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! \$\endgroup\$ Commented May 30, 2017 at 1:34
38
\$\begingroup\$

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

\$\endgroup\$
10
  • 28
    \$\begingroup\$ “move through time” wat? \$\endgroup\$ Commented Dec 6, 2016 at 19:27
  • 8
    \$\begingroup\$ @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 \$\endgroup\$ Commented Dec 6, 2016 at 19:28
  • \$\begingroup\$ @mbomb007 What exactly are you referring to? \$\endgroup\$ Commented Dec 6, 2016 at 19:35
  • 1
    \$\begingroup\$ @TùxCräftîñg I don't think I can do that \$\endgroup\$ Commented Jan 31, 2017 at 20:34
  • 1
    \$\begingroup\$ @wat Hm this took me way too long to understand \$\endgroup\$ Commented Jan 31, 2017 at 20:55
29
\$\begingroup\$

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.

\$\endgroup\$
33
\$\begingroup\$

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.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I can confirm it works in Minkolang \$\endgroup\$ Commented Dec 6, 2016 at 19:43
  • 3
    \$\begingroup\$ print('1'if 1/2else'5') breaks on my system without a space between 1/2 and else \$\endgroup\$ Commented Dec 8, 2016 at 8:58
  • \$\begingroup\$ I get the same warning (SyntaxWarning: invalid decimal literal), but it still runs. \$\endgroup\$ Commented Mar 19 at 5:33
17
\$\begingroup\$

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 ><>, 5 in Python 2, and 6 in SMBF.

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.

\$\endgroup\$
0
15
\$\begingroup\$

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, 3N.print('1'if 1/2else'5')#i2" rel="nofollow noreferrer">3 in Minkolang v0.15, 4 in ><>, 5 in Python 2, 6 in SMBF and 7 in Japt

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

\$\endgroup\$
1
  • \$\begingroup\$ More on Japt is in answer 58. \$\endgroup\$ Commented Jan 26, 2020 at 13:18
14
\$\begingroup\$

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.

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 
\$\endgroup\$
4
  • \$\begingroup\$ This is 2 bytes too long (50 + 20 is 70, 50 + 20% is 60). \$\endgroup\$ Commented Dec 6, 2016 at 20:30
  • 1
    \$\begingroup\$ @ais523 Fixed it. \$\endgroup\$ Commented Dec 6, 2016 at 20:36
  • 2
    \$\begingroup\$ Care to provide an explanation? If not, that's ok. \$\endgroup\$ Commented Dec 7, 2016 at 5:41
  • \$\begingroup\$ @MistahFiggins Sure. Added. \$\endgroup\$ Commented Dec 7, 2016 at 14:44
18
\$\begingroup\$

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.

\$\endgroup\$
9
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 6, 2016 at 22:55
  • 1
    \$\begingroup\$ 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.) \$\endgroup\$ Commented Dec 6, 2016 at 22:58
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 6, 2016 at 22:59
  • 1
    \$\begingroup\$ Err, isn't vim an interpreter for Vim? (It works in both vim and V, though.) \$\endgroup\$ Commented Dec 6, 2016 at 22:59
  • 4
    \$\begingroup\$ @ais523 maybe you can put ␛ to represent the 0x1B byte? \$\endgroup\$ Commented Dec 7, 2016 at 5:49
19
\$\begingroup\$

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.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ This makes SMBF print a null byte at the first .. \$\endgroup\$ Commented Dec 7, 2016 at 0:31
  • \$\begingroup\$ @Pietu1998 fixed! \$\endgroup\$ Commented Dec 7, 2016 at 1:31
  • \$\begingroup\$ 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.) \$\endgroup\$ Commented Dec 7, 2016 at 2:26
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Dec 7, 2016 at 2:36
  • \$\begingroup\$ 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... \$\endgroup\$ Commented Dec 7, 2016 at 5:30
19
\$\begingroup\$

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!

\$\endgroup\$
4
  • \$\begingroup\$ Heh, I wrote my 11th answer, only to realise that it had already been posted, now I changed it to the 12th answer :) \$\endgroup\$ Commented Dec 7, 2016 at 8:26
  • \$\begingroup\$ Any Idea why Vim takes so long to execute? \$\endgroup\$ Commented Dec 7, 2016 at 16:15
  • \$\begingroup\$ @MistahFiggins I guess it is because the code has to be converted to keystrokes, but other than that, I have no clue \$\endgroup\$ Commented Dec 7, 2016 at 16:16
  • \$\begingroup\$ I wrote that vim interpreter, and I have no idea why it takes so long. I haven't noticed many performance issues before, but that's because most of my V/Vim answers are less than 40 bytes. Not really sure what's causing it, but lots of people have been complaining about that on this thread. \$\endgroup\$ Commented Dec 7, 2016 at 23:00
12
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ This answer doesn't work with the Befunge93 answer, it only produces a 0 not 10. \$\endgroup\$ Commented Dec 7, 2016 at 8:54
  • 1
    \$\begingroup\$ @Tealpelican Works for me. Did you remember the ESC character between j and d on the last line? See the TIO link. \$\endgroup\$ Commented Dec 7, 2016 at 8:59
  • \$\begingroup\$ @Tealpelican tio.run/nexus/… \$\endgroup\$ Commented Dec 7, 2016 at 9:00
  • 1
    \$\begingroup\$ Yeah my bad, for some reason chrome was removing it for me. \$\endgroup\$ Commented Dec 7, 2016 at 9:23
17
\$\begingroup\$

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.

\$\endgroup\$
16
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ @Sp3000 - edited and fixed (should be) \$\endgroup\$ Commented Dec 7, 2016 at 9:34
  • \$\begingroup\$ @L3viathan - This link should work - it contains the missing ESC literal from the last line \$\endgroup\$ Commented Dec 7, 2016 at 9:48
  • \$\begingroup\$ hooray! My language is used. Also it has a capital t, unlike brainfuck \$\endgroup\$ Commented Dec 8, 2016 at 5:26
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Dec 8, 2016 at 8:42
17
\$\begingroup\$

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 
\$\endgroup\$
6
  • \$\begingroup\$ @Kade It's a nice 2D language, an online interpreter would be more helpful (although I have already downloaded the Python interpreter) :) \$\endgroup\$ Commented Dec 7, 2016 at 14:13
  • \$\begingroup\$ @Kade There is a TIO link for haystack now! \$\endgroup\$ Commented Dec 8, 2016 at 5:47
  • \$\begingroup\$ @MistahFiggins The link works for me and outputs 15 \$\endgroup\$ Commented Dec 8, 2016 at 5:58
  • \$\begingroup\$ @MistahFiggins Cache? Because it works for me without any problems or any error messages \$\endgroup\$ Commented Dec 8, 2016 at 6:00
  • \$\begingroup\$ How do you go about getting a language to be supported by TIO? \$\endgroup\$ Commented Dec 8, 2016 at 6:10
16
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ Extending in what way? I still need another 5 or so bytes available for my answer ;) \$\endgroup\$ Commented Dec 7, 2016 at 12:48
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Dec 7, 2016 at 12:51
91
\$\begingroup\$

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

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.
\$\endgroup\$
9
  • 27
    \$\begingroup\$ Where has everyone else's code gone though \$\endgroup\$ Commented Dec 7, 2016 at 14:56
  • 17
    \$\begingroup\$ 159 bytes to 128 bytes? Wow, that's some excellent golfing! \$\endgroup\$ Commented Dec 7, 2016 at 15:00
  • 8
    \$\begingroup\$ Nice, 2^7 bytes \$\endgroup\$ Commented Dec 7, 2016 at 15:45
  • 8
    \$\begingroup\$ Wow... incredible! We're going to have to write up a new explanation for every language when all's said and done ;-) \$\endgroup\$ Commented Dec 7, 2016 at 17:32
  • 4
    \$\begingroup\$ @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)" \$\endgroup\$ Commented Dec 7, 2016 at 20:07
11
\$\begingroup\$

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.

\$\endgroup\$
12
  • \$\begingroup\$ Bytes cannot be fractions, so the limit was really floor(128 * 1.2), so good thing you didn't need another byte. \$\endgroup\$ Commented Dec 7, 2016 at 19:52
  • \$\begingroup\$ Also, this is incorrect, as it prints 6\x00 in SMBF. (There are two . characters.) \$\endgroup\$ Commented Dec 7, 2016 at 19:54
  • \$\begingroup\$ Can we get the SMBF to modify out the second period? \$\endgroup\$ Commented Dec 7, 2016 at 19:56
  • \$\begingroup\$ Oh right, forgot about the second period. Shoot. \$\endgroup\$ Commented Dec 7, 2016 at 19:57
  • 2
    \$\begingroup\$ @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... \$\endgroup\$ Commented Dec 7, 2016 at 22:22
13
\$\begingroup\$

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
\$\endgroup\$
0
25
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ 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). \$\endgroup\$ Commented Dec 8, 2016 at 6:53
  • \$\begingroup\$ 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) \$\endgroup\$ Commented Dec 8, 2016 at 7:24
  • \$\begingroup\$ If you use a : to start a command in vim, you're gonna need a carriage return, which also happens to be unprintable. :/ \$\endgroup\$ Commented Dec 8, 2016 at 9:07
  • 8
    \$\begingroup\$ +10000000000 for a partridge in A Pear Tree. But does it print 5 GOLD in RINGS? \$\endgroup\$ Commented Dec 12, 2016 at 1:32
19
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ TIO now supports Cardinal \$\endgroup\$ Commented Dec 8, 2016 at 19:17
9
\$\begingroup\$

22. Underload (stringie), 174 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.

\$\endgroup\$
3
  • \$\begingroup\$ 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 \$\endgroup\$ Commented Dec 9, 2016 at 1:32
  • \$\begingroup\$ @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. \$\endgroup\$ Commented Dec 9, 2016 at 2:18
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 9, 2016 at 2:19
57
\$\begingroup\$

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.
\$\endgroup\$
9
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 9, 2016 at 5:38
  • \$\begingroup\$ I would suggest Labyrinth next, but I want to do that one. \$\endgroup\$ Commented Dec 9, 2016 at 5:46
  • \$\begingroup\$ I'm not skilled enough to write anything like this myself, but in the mean time I'm waiting for Cubix to pop up. \$\endgroup\$ Commented Dec 9, 2016 at 6:22
  • \$\begingroup\$ @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 \$\endgroup\$ Commented Dec 9, 2016 at 6:36
  • \$\begingroup\$ 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…) \$\endgroup\$ Commented Dec 9, 2016 at 7:49
13
\$\begingroup\$

24. Thutu, 211 bytes

Fourth try. Hopefully the implementation is uncontroversially valid this time.

#v`16/"<"6/b.q@"(::)::: (22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #| print((eval("1\x2f2")and 9 or 13)-(0and+4)^1<<65>>62)#@46(8+9+9+9+9+=!)=#print(17)#3]#echo 21#===2|/=1/24=x=9+/ #8␛dggi2␛` |1|6 

␛ represents a literal ESC character, as usual.

As far as I know, there isn't a Thutu implementation that works in a browser yet. I used the implementation in the Esoteric Files Archive, which is a compiler from Thutu to Perl (basically, compile the Thutu into Perl, then run the Perl). Update: Since I wrote that, the language has been added to TIO. So now you can:

Try it online!

This program prints 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (test 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.

I had to pretty much redo the Hexagony part of the solution. It turns out to be easiest to run the Hexagony code on a diagonal, rather than horizontally:

 # v 1 6 / " < " 6 / b . q @ " ( : : ) : : : ( 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 ( ( e v a l ( " 1 \ x 2 f 2 " ) a n d 9 o r 1 3 ) - ( 0 a n d + 4 ) ^ 1 < < 6 5 > > 6 2 ) # @ 4 6 ( 8 + 9 + 9 + 9 + 9 + = ! ) = # p r i n t ( 1 7 ) # 3 ] # e c h o 2 1 # = = = 2 | / = 1 / 2 4 = x = 9 + / # 8 ␛ d g g i 2 ␛ | 1 | 6 . . . . . . . . . . . . . . . . . . . . . . 

The bold font doesn't show up that well for me, but nonetheless, I've boldened the route that the IP takes. There's only one IP used, this time, and it hardly runs any commands. The program starts by pushing some junk to the memory edge, then replacing its value with the sum of the memory edges to either side (which still have their initial value of 0), thus resetting memory to all-zeroes. Then we can just do 23!@ to print 23 and exit.

Thutu doesn't like blank lines. As such, I had to replace Retina's blank line (which matches anything) with #| (which also matches anything).

Thutu also cares a lot about slashes; they're the main syntactical element of the language. Luckily, # at the start of a line is a comment in Thutu, so we only have one line to worry about. However, # inside a line is not a comment, so the big long line is something of a concern. As such, I had to hide the slash from Thutu by placing it inside an eval. Luckily, both versions of Python, Perl, and Ruby all have an eval, and will all unescape \x2F into / inside a string delimited by ". Unfortunately, the use of " makes the code live in Pyth, and can easily cause syntax errors (e.g. eval("1\x2F2") is a syntax error), but we can use a lowercase \x2f and Pyth will be OK with that, at least syntax-wise (it's in a part of the code that never runs, so we don't have to worry about what it actually does).

Thutu interprets most of the big long line (up to the first slash) as a regular expression. As such, the Prelude code was causing problems, as +++ is too much quantification. However, it was fairly easy to fix that by re-associating the uses of +.

So how does the Thutu work? Most of the code is a comment, with only one line of code. Thutu's kind-of like Retina; it works by repeatedly regexing a working space. Initially, the input is =1. We first check to see if it matches the regex print(( … ===2| (it does, because most (all)? regexes ending with | will match anything). Then we replace one occurrence of =1 with 24=x=9+. At the end of each cycle, the Thutu implementation will output everything before =x (i.e. 24), exit (due to the presence of =9), and keep the + (which we don't care about) for the next cycle (which doesn't exist).

In terms of places where code can be added, the main offender is Hexagony, which is incredibly fragile in the current case. As such, I suspect that the last line is currently the easiest place to add code if you don't want to redo a large amount of work. The 6 at the end is used for SMBF, but the |1| is used only by Retina, which can cope with any other regex there that's matched a lot of times, and Vim; a few 2D languages will pass over the line but will consider most characters fairly harmless. Before the first ESC is touched even less, with only Retina caring (although if you go too far right, you'll affect some 2D languages, like before). Note that there's a limit to how long the code there can be, because if the Hexagony side length gets thrown off, everything will break.

If you're willing to redo the Hexagony, the long line is still a good place to add code, although slightly worse than before. The ===2 is purely Hexagony, and will hardly be seen by other languages (although Thutu wants it to be a valid regexp, Prelude doesn't want parentheses or exclamation marks, SMBF doesn't want periods or mismatched brackets). Earlier in the line (the #@) is also a safe place to add code so long as you're careful with Thutu and SMBF, and redo the Hexagony; you may need to add a 0 or two at the end of your code to prevent it confusing the Prelude code later.

Finally, if you're prepared to dodge the 2D languages, the #| line is pretty much entirely free, with only Retina and the occasional wild two-dimensional instruction pointer causing problems.

\$\endgroup\$
0
11
\$\begingroup\$

25. Pip, 220 bytes

#v`16/"<"6/b.q@"(::)::: (22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #| print((eval("1\x2f2")and 9 or 13)-(0and+4)^1<<65>>62)#@46(8+9+9+9+9+=!)=#print(17)#3]#echo 21#===2|/=1/24=x=9+/ #8␛dggi2␛` |1|6//1''19+6 

represents a literal ESC character, as per previous submissions.

This program prints 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (test 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.

The 1|6 is used by both Retina and Japt and the // serves to comment out the end of the code so that Japt doesn't output anything else. I feel like 26 should be fairly 'easy' to sneak into the end since SMBF needs a trailing 6, so anything that will output the last item in the code (being 26) should be at an advantage... Perhaps 05ab1e? Good luck!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I had a look at 05AB1E. It almost works very easily; the main issues are Hexagony (this one's easily solvable), Pip, and Japt. (The problem is that Pip comments start with two spaces, and Japt doesn't like that at all, because a space is the equivalent of a closing parenthesis; this causes Japt to add opening parentheses to the start of the program to balance, leading to a syntax error because the closing parentheses are commented out.) 05AB1E next still seems like a good idea – it'll output 26 for almost any program ending 26 – but maybe you'll have to move the Pip earlier. \$\endgroup\$ Commented Dec 14, 2016 at 15:35
  • \$\begingroup\$ Followup: $// works as a comment marker in Japt that's happy to see spaces later on the line. I might have another try in a bit, but if someone else wants to get there first, go for it; testing a program in 26 different languages is exhausting. (Also, it's too late to edit my previous comment, but I should have said "almost any program ending "26".) \$\endgroup\$ Commented Dec 14, 2016 at 15:44
  • \$\begingroup\$ @ais523 Agree about tiring testing, such hard work! What's annoying is finding a problem in Japt and having to re-test the others! I did really enjoy this challenge though. I wonder if there's a record for the smallest polyglot with most languages... \$\endgroup\$ Commented Dec 14, 2016 at 15:45
  • \$\begingroup\$ The problem is precisely that // is a comment marker in Japt, but Japt doesn't know it's a comment marker, so it tries to balance parentheses in it and ends up making things worse. $// avoids that problem by telling it not to parse the stuff until the next dollar. \$\endgroup\$ Commented Dec 14, 2016 at 15:46
11
\$\begingroup\$

26. 05AB1E, 224 bytes

#v`16/"<"6/b.q@"(::)::: (22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #| print((eval("1\x2f2")and 9 or 13)-(0and+4)^1<<65>>62)#@46(8+9+9+9+9+=!)=#print(17)#3]#echo 21#===2|/=1/24=x=9+/ #8␛dggi2␛` |1|6//1"'"'--1+26 

represents a literal ESC character, which you likely know by now if you're here, but I'm reminding you just in case.

This program prints 26 in 05AB1E, 25 in Pip, 24 in Thutu, 23 in Hexagony, 22 in Underload, 21 in Nim, 20 in Prelude, 19 in Reng (test 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.

I wish I could explain this a bit, but I mostly just stumbled through this blindly. Never heard of/used 05AB1E or Pip, and never used Pyth (which gave me the most trouble).

05AB1E saw most of the program as an unclosed string (from ")and 9 onwards), so that needed to be closed. Pip and Pyth didn't cooperate with the extra double quote initially, which turned into trial and error of single/double quote placement until they complied.

The exact math used for Pip was mostly arbitrary, as long as it resulted in 25, so toying with that got me a plain 26 at the end for 05AB1E while still calculating the 25 needed for Pip.

\$\endgroup\$
1
  • \$\begingroup\$ You should probably note that you need to pipe in empty input for this to work (e.g. < /dev/null), otherwise the interpreter hangs waiting for input \$\endgroup\$ Commented Dec 17, 2016 at 8:53
22
+50
\$\begingroup\$

27. Perl 6, 235 bytes

#v`16/"<"6/b.q@"(::)::: (22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #`<`| print((eval("1\x2f2")and 9 or 13)-(0and 4)^1<<65>>62)#@46(8+9+9+9+9+=!)=#print(17)#3]#echo 21#===2|/=1/24=x=90/ #8␛dggi2␛` |1|6$//''25 #>say 27#"26 

␛ represents a literal ESC character, as usual.

This program prints 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, and (as it's Christmas) a partridge in A Pear Tree.

The syntax highlighting that Stack Exchange produces for this answer is completely wrong. #`< is one of Perl 6's many multiline comment markers, and ends at #>, thus the only code that actually runs in Perl 6 is the very simple say 27. I chose this particular comment marker because <> aren't a matching pair in most languages, and thus the unmatched < won't break languages, such as Retina, that attempt to parse it.

I'm not entirely sure how the Hexagony works any more. When it broke, I changed one of the characters it was using from a + to a 0 to see if it was being hit; turns out it was, and turns out this fixed the program, but I'm not sure why (I know it broke due to a # in the line of execution, but it's unclear why removing the + fixes things). (The character in question is also parsed by Thutu, but luckily this doesn't make a difference to the functioning of the Thutu program, as at that point in the program, anything that isn't preceded by an = is copied literally into the working string.) Note that the 0and+4 from a previous line became 0and 4, to make it one character shorter from Hexagony's point of view (Hexagony doesn't see spaces); this is to compensate for the #| on a previous line becoming #`<`|, which is one character longer from Hexagony's point of view (because it doesn't see backquotes either). Note that the code's now only five bytes away from expanding the Hexagony side length and breaking everything about the current Hexagony code. I'd recommend doing this anyway and just redoing the Hexagony section of the code; it'll probably be easier, rather than harder, to fit everything in after an expansion.

Some other languages changed too, mostly to add enough robustness that I could fit arbitrary code in on the last line. $// is a comment marker in Japt that allows spaces later on the line, making the added program less fragile in Japt (meanwhile, // breaks if there are any closing parentheses later on the line, and space is a sort of closing parenthesis in Japt). A pair of spaces is a comment marker in Pip, meaning that the Pip code can be substantially simplified here. This also means that we can simplify the 05AB1E down to a trivial "26. Retina needs the fifth line to be a legal regex that's good at matching things (the trailing | is thus for Retina); it parses differently from the corresponding line in the previous entry, but in a way that's just as suitable. The Cardinal is also very slightly simpler than in previous entries, but this is just pure coincidence with how everything lines up vertically, and the change is to code that didn't do anything anyway.

Assuming you redo the Hexagony (you'll probably have to), there are safe places to add code on all of the last three lines: the 3 in #3]# is only for Hexagony (and easily changed); the space between the # and " on the final line is ignored by the vast majority of languages; and nothing's really parsing the end of the fifth line other than Retina. (There are plenty of other places where code can be added, too, but these are probably the most convenient.)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I accidentally downvoted this answer and noticed I downvoted when i noticed my rep's gone down by 1. Can you edit the answer so I can upvote? :D \$\endgroup\$ Commented Dec 25, 2016 at 9:37
  • 6
    \$\begingroup\$ @betseg: I added a bit more discussion of the Hexagony, just for you. \$\endgroup\$ Commented Dec 25, 2016 at 12:37
  • 2
    \$\begingroup\$ Congrats on the bounty! I wanted to get this post moving again :P \$\endgroup\$ Commented Dec 25, 2016 at 15:26
  • \$\begingroup\$ I'd been planning to continue it for ages, it was just a case of trying to find the time. (I'd actually made a failed attempt at Perl 6 a while back, earlier in the chain, and didn't post it because it didn't work. Luckily, I learned from the mistakes and it works this time.) \$\endgroup\$ Commented Dec 25, 2016 at 21:19
29
\$\begingroup\$

28. Brain-Flak, 280 bytes

#v`16/"<"6/b.q@"(::)::: (22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #`<`| print((eval("1\x2f2")and (9) or (13))-(0and 4)^(1)<<(65)>>62)or'(\{(\{})(\{}\/^23!@[()])}\{})(\{}\{})'#@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 /^23!@ 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 '(\{(\{})(\{}\/^23!@[()])}\{})(\{}\{})'. 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 /^23!@. 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!

\$\endgroup\$
4
  • \$\begingroup\$ 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!) \$\endgroup\$ Commented Dec 28, 2016 at 4:39
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 28, 2016 at 8:17
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Commented Dec 28, 2016 at 16:21
  • 2
    \$\begingroup\$ Fantastic answer, and a very thorough explanation! I'm really happy to hear that you enjoy brain-flak. :D \$\endgroup\$ Commented Jan 2, 2017 at 18:59
11
\$\begingroup\$

29. Trigger, 292 bytes

#v`16/"<"6/b.q@"(: ::T): :(22)S#;n4"14" #>3N6@15o|> ^*ttt*~++~~~% #=~nJ<R"12"; #[ #`<`| print((eval("1\x2f2")and (9) or (13))-(0and 4)^(1)<<(65)>>62)or'(\{(\{})(\{\/+23!@=}[()])}\{})(\{}\{})'#@46(8+9+9+9+9+=!)=#print(17)#]#echo 5+5+11#|/=1/24=x=90/ #8␛dggi2␛` |1|6$//''25 #>say 27#T222999"26 

This program prints 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 (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 V/Vim, and 1 in Python 3.

Something must have been working in my subconcious in the time since the last submission to this challenge, because by the point I decided it was running low on time and I wanted to ensure it wouldn't die, I suddenly remembered a language from years back that could be added fairly easily as seen by the low increase in the byte count, and quite a bit of that was due to Hexagony rather than Trigger itself. Except for commands that assign to variables (which mostly don't matter), all Trigger's commands contain two consecutive equal characters. The first time this happens is in the Underload code in the first line, so I simply modified that a bit to jump to almost the end of the program, and placed the Trigger code to print 29 (which is 222999) there. The jump label I used is T (originally I tried U but Fission disliked it), but if you need to use a capital T in your own program for some reason, you can easily change both occurrences to something else that isn't used in your program.

Very little else needed changing, apart from (as always) the Hexagony. I decided it was time to stop messing around with formatting the code into a hexagon by hand, but luckily we've already had a challenge about Hexagony parsing, so I went and modified this answer to the challenge into an online-usable Hexagony formatter that handles backticks correctly (here). Here's how this version of the program looks as a hexagon:

 # v 1 6 / " < " 6 / b . q @ " ( : : : U ) : : ( 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 ( ( e v a l ( " 1 \ x 2 f 2 " ) a n d ( 9 ) o r ( 1 3 ) ) - ( 0 a n d 4 ) ^ ( 1 ) < < ( 6 5 ) > > 6 2 ) o r ' ( \ { ( \ { } ) ( \ { \ / + 2 3 ! @ # } [ ( ) ] ) } \ { } ) ( \ { } \ { } ) ' # @ 4 6 ( 8 + 9 + 9 + 9 + 9 + = ! ) = # p r i n t ( 1 7 ) # ] # e c h o 5 + 5 + 1 1 # | / = 1 / 2 4 = x = 9 0 / # 8 ␛ d g g i 2 ␛ | 1 | 6 $ / / ' ' 2 5 # > s a y 2 7 # U 2 2 2 9 9 9 " 2 6 . 

You might well have noticed that the Nim code is more verbose than it used to be. This is purely because padding it out as 5+5+11 rather than 21 happened to make the Hexagony line up perfectly; if you start at the / of /+23!@#, you can see an uninterrupted run of Hexagony-safe characters, and that's how I made that part of the program work.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ +1 for the updated hexagony formatter. Are there any online resources for testing in Trigger? I think it may have blown out my next solution. :P \$\endgroup\$ Commented Jan 5, 2017 at 17:00
  • \$\begingroup\$ @Chance: Not yet, although I put in a request for it on TIO. Also, I'd be both surprised and upset if Trigger ended up blocking a language, because it's fairly easy to work into a polyglot; it doesn't parse code you jump over, and its jumping ability is fairly flexible. \$\endgroup\$ Commented Jan 5, 2017 at 17:16
  • \$\begingroup\$ Yeah, I've been digging into some turing tarpits with limited character sets, which had a lot of repeated characters as you'd expect. I'll read up about Trigger's jumping ability though. Maybe it is workable. \$\endgroup\$ Commented Jan 5, 2017 at 17:40
  • \$\begingroup\$ @Chance: The : ::U in the current program jumps to the U at the end. Everything in between won't even be parsed, so you can repeat as much as you like there. \$\endgroup\$ Commented Jan 5, 2017 at 18:31
  • \$\begingroup\$ /+23!@= != /+23!@# \$\endgroup\$ Commented Mar 10, 2017 at 17:16
27
\$\begingroup\$

30. Whitespace, 296 bytes

#v`16/"<"6/b.q@"(: ::T): ␉␉␉␉ :(22)S#;n4"14" #>3N6@15o|>␉^*ttt*~++~~~% #=~nJ<R"12"; ␉ #[␉ #`<`| print((eval("1\x2f2")and (9)or(13))-(0and 4)^(1)<<(65)>>62)or'(\{(\{})(\{\/+23!@}[()])}\{})(\{}\{})'#46(8+9+9+9+9+=!)=#print(17)#]#echo 21#|/=1/24=x=90/ #8␛dggi2␛␉` |1|6$//''25 #>say␉␉ 27#T222999"26 

␛ represents literal escapes.

␉ represents literal tabs.

This program prints 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 (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 V/Vim, and 1 in Python 3.

Whitespace is another esolang with a limited character set. This one only reads tabs, spaces, and line feeds.

So once we take out all the stuff that Whitespace doesn’t read we’re left with the following code:

[space][space][space][LF] [space][LF] [LF] [LF] [LF] [space][space][space][space][space][LF] [space][space][space][space] 

And the code to output 30 is this:

[space][space][space][tab][tab][tab][tab][space][LF] [tab][LF] [space][tab] 

So the top 3 lines of the existing code were given extra spaces at the end of lines to meet the requirements. Note that line 1’s tabs and trailing space are in the middle of the line to accommodate ><>’s needs.

Line 2’s space was changed to a tab here. This seems to function Identically to a space for the 2D languages, but visually it doesn’t line up anymore. ¯\_(ツ)_/¯

After the instructions to output 30, the game became getting the rest of the necessary spaces and line feeds to do pointless things and compile correctly.

White space happens to have instructions that mark/goto a code location with a label that allows for an arbitrary number of tabs and spaces, so that helped couch the long line’s spaces. It also starts and ends with a line feed, so that helped us up some of the line feeds in lines 3-6.

The final line couldn’t have a linefeed without breaking Retina, so its instructions are to do some arbitrary math and stack manipulation.

Here’s the full code with spaces, tabs, and linefeeds replaced with our notation:

#v`16/"<"6/b.q@"(:[Space]::T):[Space][Space][Tab][Tab][Tab][Tab][Space]:(22)S#;n4"14"[LF] #>3N6@15o|>[Tab]^*ttt*~++~~~%[LF] #=~nJ<R"12";[Space][Tab][LF] #[[Tab][LF] #`<`|[LF] print((eval("1\x2f2")and[Space](9)or(13))-(0and[Space]4)^(1)<<(65)>>62)or'(\{(\{})(\{\/+23!@}[()])}\{})(\{}\{})'#46(8+9+9+9+9+=!)=#print(17)#]#echo[Space]21#|/=1/24=x=90/[LF] #8␛dggi2␛[Tab]`[Space]|1|6$//''25[Space][Space]#>say[Tab][Tab][Space]27#T222999"26[LF] 

And here is a commented version of just the Whitespace:

Push 30 onto the stack [space][space][space][tab][tab][tab][tab][space][LF] Output the number at the top of the stack [tab][LF][space][tab] Jump to label null if the top of the stack is negative. (it's not) [LF][Tab][LF] Label this location as [Space] [LF][Space][Space][Space][LF] Add the top two items on the stack and replace them with the result. [Tab][Space][Space][Space] Store the stack. [Tab][Tab][Space] 

Edits: Hexagony turns out to skip over tabs just like spaces, contrary to my previous assertion. @ais523 was kind enough to update @Kenney's Hexagonizer to account for literal escapes and tabs. I had to modify it to correct my prior assertion about tabs being read as no-ops and to replace literal escapes with . because the character is wider than other characters, making the hex slightly misaligned. Here the link.

And this is our corrected current Hex:

 # v 1 6 / " < " 6 / b . q @ " ( : : : T ) : : ( 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 ( ( e v a l ( " 1 \ x 2 f 2 " ) a n d ( 9 ) o r ( 1 3 ) ) - ( 0 a n d 4 ) ^ ( 1 ) < < ( 6 5 ) > > 6 2 ) o r ' ( \ { ( \ { } ) ( \ { \ / + 2 3 ! @ } [ ( ) ] ) } \ { } ) ( \ { } \ { } ) ' # 4 6 ( 8 + 9 + 9 + 9 + 9 + = ! ) = # p r i n t ( 1 7 ) # ] # e c h o 2 1 # | / = 1 / 2 4 = x = 9 0 / # 8 . d g g i 2 . | 1 | 6 $ / / ' ' 2 5 # > s a y 2 7 # T 2 2 2 9 9 9 " 2 6 . . . . . . . 

Finally, I golfed out some needless characters, mostly added previously to line up Prelude parenthesis and Hexagony hexagons.

Nim’s code is back to echo 21 from echo 5+5+11

Hexagony’s #@46 is now #46

Hexagony’s code is back to /+23!@= from /+23!@

Prelude’s parenthetical alignment of (9) or (13) became (9)and(13)

Well, that’s all I got. Good Luck everyone!

\$\endgroup\$
14
  • 1
    \$\begingroup\$ I think I fixed all the links and added ␛ in places of the space that resulted from my copy pastes. Not sure how to get tabs to be tabs in SE, the code in Tio should disambiguate. I also had to re-create my solution from the instructions in this answer, but somehow ended up with 2 fewer bits... Oops? \$\endgroup\$ Commented Jan 6, 2017 at 2:35
  • 1
    \$\begingroup\$ Just noticed a mistake in your explanation: carriage return (ASCII 13) is a different character from line feed (ASCII 10). The vast majority of languages (including Whitespace) care about the 10s, not the 13s (and it's assumed that a line break in a PPCG submission is just a single ASCII 10 unless otherwise stated, because the 13s tend to inflate your byte count to no benefit). \$\endgroup\$ Commented Jan 6, 2017 at 3:43
  • 1
    \$\begingroup\$ Your hexagony explanation image is wrong (prints e23) because of ; after the e when coming up NW after first reflection. The above link works tho...? \$\endgroup\$ Commented Jan 6, 2017 at 6:34
  • 1
    \$\begingroup\$ I have come to the conclusion that the TIO for Hexagony treats tab characters as spaces/newlines. The image you provide of the hexagony program does nothing but exit if you follow it (or put it into TIO, replacing tabs with .s). However, copy the code in the image into TIO, except remove the training .s (not part of the actual code) and all the ␉s. It prints 23. \$\endgroup\$ Commented Jan 6, 2017 at 6:58
  • 1
    \$\begingroup\$ Wow, thanks @MistahFiggins! It looks like I made some deductive errors and propagated them to my explanation. I've corrected the Hexagony explanation, hex diagram, and Hexagonoizer Perl script, as well as cross checked the result against Hexagony directly. Everything should be good now. Good Find! \$\endgroup\$ Commented Jan 6, 2017 at 16:45
1
2 3 4 5
16