Print your char count in words, in many languages

18

1

This challenge is inspired by my earlier challenge "Create a program that prints the amount of characters it has, in words".

This challenge's rules are simple: make a program that prints its character count, in words, which works in as many languages as possible.

Each programming language the program works in must make the program print its char count in a different natural language.

E.g. you can make a polyglot which prints "fifty" (suppose this is its char count) in one language and "pedeset" (Serbocroatian for 50) in another, but not a polyglot printing "fifty" in both languages.

An extension to the "don't invent languages to solve the task" rule also applies here: don't make a constructed language just to validate your otherwise nonsense output in some language.

If the polyglot printing "fifty" in one language was tested in another and printed (prant?) "Aijsisdjdsl", it's illegal to make a conlang using "Aijsisdjdsl" as the word for "fifty".

Capitalization is ignored: in case you're printing "one" (somehow) you can print "one", "oNe", "ONE" or anything else.

Base ten is required.

Proper spacing is also required.

In the (unlikely but just for specification) case your program reaches one billion characters or more, use the American number scale. A billion here is 10^9 and a million is 10^6.

Do not use "one hundred and one": use "one hundred one".

Do not use the hyphen. Print forty four, not forty-four.

If the language you use has another script, use it instead of the romanization of it. If your program prints Arabic in some language, it should print (yet again, example with 50) "خمسون" and not "khamsun".

Use the grammatically correct translation.

For our purposes, we use Ethnologue to determine what is and isn't a language in this challenge. It's the most widely used so we'll just go with that.

For simplicity, any languages with identical numerals will be considered the same for this challenge. Using any Japanese/Chinese numeral gives you a score of 1.

If a word is spelled the same in multiple languages, e.g. English and French's "six", it counts as one point toward your score.

Dialects Ethnologue differentiates will be considered different languages as long as they don't fall in the two rules above.

Different compilers of the same programming languages are not differentiated here.

Your score is the amount of languages your program works in, per standard rosetta-stone rules.

If the two (or more) best answers are tying, the one with the lowest byte count wins.

The encoding used to determine byte count for tiebreakers is UTF-8.

The highest score wins (in case of tie see above). Have fun.

Andrew

Posted 2019-10-22T13:57:06.433

Reputation: 2 067

Do the same rules apply as in your previous challenge regarding output, or are we allowed to choose which format to output in this time? So is it mandatory to output hundred thirty four instead of one hundred and thirty-four, or are both allowed? And does this also apply to other languages (i.e. in Dutch: honderd dertig vier - which literally translates as the three words hundred thirty four, instead of honderdvierendertig - which would be the grammatically correct translation for one hundred and thirty-four)? I would allow both variations, or else the grammatically correct one. – Kevin Cruijssen – 2019-10-22T14:19:58.903

2It might also be a good idea to link to your previous challenge, and copy some of its rules to here, since challenges should be self-contained. – Kevin Cruijssen – 2019-10-22T14:30:32.920

2I only notice this now, but what is the win condition of the challenge? I don't see a code-challenge tag, nor any indication on the scoring? Reading the challenge I assumed the more languages the better the score, and byte-count if the amount of languages are equal (since that's usually the case), but I don't see this in the challenge description.. Right now this would be closed as "doesn't have a clear winning condition".. – Kevin Cruijssen – 2019-10-22T14:57:28.313

If a number is spelled the same in multiple languages, is that considered different for this challenge? For example, "six" in English and French. – 79037662 – 2019-10-22T15:25:39.707

1In case anyone's interested, 100 is "백" in Korean, "百" in Chinese, "ひゃく" in Japanese(Hiragana, because Kanji is all the same in CJK). 1000 is "천" in Korean, "千" in Chinese, "せん" in Japanese. – Bubbler – 2019-10-23T06:37:28.327

1[tag:rosetta-stone] is not a scoring criterion, though it feels like it should be. Please use [tag:code-challenge] – Jo King – 2019-10-23T10:13:29.673

Can we output trailing whitespace? – None – 2019-10-23T10:20:45.533

Is it generally accepted that different C compilers are different languages for polyglotting? – None – 2019-10-25T10:16:37.507

1Do dialects count as separate natural languages? (I am not referring to programming languages in this case.) – None – 2019-10-25T10:17:57.063

Here's the rule in short: if Ethnologue says it's separate, then it's a separate language, unless the two languages use the same numerals system. If two separate numbers have at least one number spelled the same and you are using it, one point to you. – Andrew – 2019-10-25T22:34:05.037

Answers

31

9 10 12 13 16 18 21 23 languages, 1000 bytes

  • Bash (prints "duizend", Dutch)
  • Zsh (prints "een Dausend", Luxembourgish)
  • Dash (and other true POSIX shells) (prints "nje mije", Albanian)
  • C (prints "et tusind", Danish)
  • C++ (prints "ib txhiab", Hmong)
  • brainfuck (prints "mille", Italian)
  • boolfuck (prints "afe", Samoan)
  • Brainlove (prints "mil", Spanish)
  • 2DFuck (prints "sewu", Javanese)
  • Python 1 (prints "one thousand", English)
  • Python 2 (prints "eintausend", German)
  • Python 3 (prints "hal kun", Somali)
  • Asar (prints "tuhat", Estonian)
  • ><> (prints "jedna hiljada", Bosnian)
  • Gol><> (prints "eenduisend", Afrikaans)
  • Befunge-98 (prints "o mie", Romanian)
  • Befunge-96 (prints "otu puku", Igbo)
  • Labyrinth (prints "elf", Maltese)
  • Hexagony (prints "ett tusen", Swedish)
  • GNU Make (prints "isang libo", Filipino)
  • A Pear Tree (prints "hezar", Kurdish)
  • Octave (prints "tūkstantis", Lithuanian)
  • Whispers (prints "seribu", Malay)
#ifdef    warnings //[[^
#_ if 0
#{
#(________ )
'''''echo' -n<<"'''+r'''":
    @echo   "isang libo"
define N #
1_801_201_
0
1...@
endif
print "tuhat"
macro _()
#}
disp("t\xc5\xabkstantis")
quit
#{
> "seribu"
>> Output 1
'''+r''':
[ -n "$ZSH_VERSION" ]&&echo een Dausend||([ -n "$BASH_VERSION" ]&&echo duizend||echo nje mije)
:<<"endmacro;\"^*///]\"\"\"#/t#"
#endif
#include<stdio.h>
int main(){puts(sizeof('1')-1?"et tusind":"ib txhiab");}
/*
print"hezar";exit;<<'/*';#NJ@G@GMCI
1234567890123456789012345678901234567890123|u;ts;6ie$;;tn;e@$<
]+[+++[[<+>->+++++>+<<]+>]<<<.<.+++.(.<.)>>+;+;;;;+;;+;;+;;+;;+;;+;+;+;+;+;;+;;+;[-]]![!.!...!..!..!.!..!..!.!.!.!.!...!.!...!.!...!.!.!.!.!][
'''
print(["hal kun","eintausend","one thousand"][(type(1==1)==type(1))+(3/2==1)])
r""""
01234567891234567890123456789012                               1
                       >"ukup uto">:#,_@
                H"eenduisend"\
        >o<"jedna hiljada"~\ u
#}
endef #   >"eim o"4k,@ /"`"/"/"\
endmacro;"^*///]"""#/t#

There should be a hard tab at the start of line 6.

Try it online! (use the switch languages button to try them all)

Length is exactly 1000 ASCII characters, and also 1000 bytes.

Asar is a SNES assembler that has quite sloppy input parsing and thus accepts a lot of inputs that one may consider invalid. I used version 1.71 for this, downloadable here, and depended on quite a few bugs, so there is a chance this will break in later versions.

All of the other languages are well-known enough to be on TIO.

I used Google Translate for the translations, so they may not be perfectly grammatically accurate. If anyone knows some of the languages better, please suggest improvements, I've got some wiggle room here :)

Credits: @JoKing for some minor optimizations regarding brainfuck, befunge, (gol)><>, hexagony, and python. @flawr for suggesting and helping with octave. @caird coinheringaahing for suggesting whispers.

Fun fact: I made most of this polyglot months ago. It included the first 10 languages mentioned here. (edit: I've since shuffled the language list around a bit so it makes more sense, but check the 2nd oldest version of this polyglot in the edit history and add hexagony to get that list).

Explanation (slightly outdated)

This explanation was made for an older revision. It's hard enough keeping track of all the natural language shuffling (to make more difficult programming languages use shorter natural language words) and Hexagony's constant grid shifting, let alone update the explanation every single revision. I'm leaving this here since it still gives a good overview of how what path most of these languages take.

Asar

Asar is a SNES assembler written by Alcaro in 2011, intended to be backwards-compatible with xkas (written by byuu in around 2006). It doesn't have the nicest code. The first line begins with a special kind of label definition, the label is called ifdef. Then follows a warnings command, which is supposed to control when warnings are thrown. Usually it's followed by either push or pull, but it doesn't reject other words following it. So that's the first line: a label-definition followed by a no-op. The 2nd line is a similar label definition (this time the label is called simply _) followed by an if statement. The condition is 0, so the contents of the if are ignored. This means we can pretty much go wild inside it, the only rule we have to follow is that all double-quotes must be paired. The end of that if statement is at the endif on line 10. After that comes a simple print statement which prints the output. Then comes a macro declaration. Declaring a macro that isn't used is pretty much equivalent to an if 0. The end of the macro declaration is on the very last line. In Asar, comments are started with ;, so the rest of the last line is ignored.

Bash, Zsh, Dash

The first 3 lines are just regular comments. The 4th line is equivalent to echo -n <<"'''+r''':". This is an echo without a linebreak following it. Then we have a heredoc that ends at any occurrence of '''+r''':. The contents of the heredoc are piped to the stdin of that echo command, but that doesn't matter since echo ignores its stdin. After the end of the heredoc on line 14, we have regular shell code that checks whether the variables for either zsh or bash are defined and chooses what to print based on that. After that, we have the null command :, which does nothing, into which we pipe the rest of the script using another heredoc. The heredoc ends with endmacro;"^*///]"""#/t#, which just happens to be the very last line of the script.

C, C++

The first line is a preprocessor directive which checks whether the define "warnings" is defined. There's also a comment after the directive. warnings isn't defined, so the contents of the block are skipped. There are a bunch more garbage preprocessor directives inside the skipped if branch, but they are ignored too. The #endif is on line 18. After that we have a standard C program. It checks whether the size of a character literal is greater than 1 or not. If it's greater, we are in C, because in C character literals are actually of int type, which has a size of at least 2 bytes on literally every platform in use today. In C++, however, the type of a character literal is char, which is defined to have a size of 1, so a different branch is taken. The rest of the code is a single comment, started with /* at line 21. It's terminated in the middle of the last line, but followed immediately by a single line comment.

Brainfuck

On the first line, we have 2 open brackets. This is because one of them is eaten by the heredoc that ends the shell part, which is before the brainfuck part. There are some balanced brackets within the skipped part too, but they don't matter because they are balanced. The next closing bracket is on line 21, which is also the start of the brainfuck code. I used this text-to-brainfuck converter, because somehow it generated even better output than BF-Crunch. Then follows the boolfuck code, which is mostly ignored due to ; not being defined. The increments don't matter either, we just switch to the next cell which has never been written to so the next open bracket is a guaranteed jump. The next closing bracket after that is on the very last line, and there are no brainfuck instructions after it.

Boolfuck

The boolfuck control flow is quite similar. However, once the brainfuck code is reached, most of it is ignored as - isn't defined in boolfuck. The area with + and ; is where the output is actually printed. It just prints the string "mil" bit by bit, with + negating the current bit and ; outputting it. The rest of the control flow is identical to brainfuck.

Python 1, 2, 3

The first 3 lines are regular comments. The 4th line starts with a triple-quoted string literal, delimited by single quotes. This string literal is often closed and reopened because I needed to get a backslash in somewhere (I've forgotten where), so I needed the string literal to be raw, but I couldn't put the r before the first quotes. Anyways, the first place where the string literal is closed and not immediately followed by another string literal is on line 23, which is the start of the Python code. This code uses a few simple tests to determine which version of Python it's running on: in Python 1.6, there was no separate boolean type, so the results of comparisons were just ints. The first condition checks that. The second condition checks whether division rounds down or not. In Python 2, division on integers rounded the result down, whereas in Python 3, it results in a floating point answer. After the Python code, we have another raw string literal that lasts until the last line, where it is immediately followed by a comment.

><>, Gol><>

Now we get to the 2D languages. Gol><> is almost perfectly backwards compatible with fish, so they start execution the same way. In fish, execution starts from the north east ("top left") corner of the program, with the instruction pointer pointing west. In fish, # is a mirror which reflects the instruction pointer back in the direction it came from. The # causes the IP to point west instead. In fish, program space is topologically a torus, so going off the western edge results in reappearing at the eastern edge of the program. There it encounters ^, which changes the instruction pointer's direction to north. Execution then continues from the very bottom of the script. The IP goes right past the very last character of the program and hits the / on line 31. The / reflects the IP like a mirror, so it'll go east again. Here is where we determine if we are running fish or golfish. In golfish, quotes inside string literals can be escaped with `. So in golfish, the string literal is only terminated on the 3rd quote on that line. In regular fish, however, the backtick escape doesn't exist, so the string literal ends after the 2nd quote. (The 4th quote is needed to keep Asar happy about paired quotes). Then, both IPs are reflected upwards. The fish one goes west on line 30 and follows a pretty simple text printing program. The golfish one goes west on line 29, after switching to a different stack with the u in its path on line 30. There, it follows a very simple string printing code too (just push the string on the stack and call H, which exits and dumps the whole stack as ASCII text).

Befunge-98

In Befunge-98, execution starts out in the north west ("top left") corner of program space, pointing east. # is a trampoline command, it skips the next instruction. The letters a-f just push their hex value on the stack. Spaces are no-ops. w pops 2 items from the stack, compares them, and turns left or right depending on which one is larger. here, f is larger than e (15 is larger than 14), so we turn left, with the IP pointing north. Now we jump to the bottom of the program, like in fish, and follow the path of arrows to line 31. This uses a simple string printing code with the k operator, which repeats the next instruction (print character) some number of times, 5 in this case.

Hexagony

This was the one language that probably costed me the most time while writing this thing. This explanation is a bit oversimplified, go look at Hexagony's README or wiki page if you want to learn more. Hexagony reformats your program into a hexagon. Then execution starts at the north-west corner. The first command, #, switches to the IP with the index of the current memory cell (there are 6 IPs, each one starting at a different corner of the hexagon). Memory is initialized to all 0's though, so this switches to the first IP, which is the one that is already executing. All alphabetic characters simply set the current memory cell to their value, so most of the rest of the 1st line is just no-ops. Then there's a mirror, /, which makes the IP point north-west (as if it got reflected off the mirror). This means the IP will wrap around to the very bottom of the hexagon. There, it happens to hit the / at the very end of the script. This is also a mirror and makes the IP go east again. Then we set the current memory cell to t and use the "switch IP" command again. Since there are only 6 IPs, the current memory cell is taken modulo 6 when switching, so it goes to the 3rd IP, which starts at the eastern corner of the hexagon. This IP starts out moving southwest and it executes some useless operations before reaching the end of line 23 in the original code. There it uses the $ operator to skip over some characters the first time around, then encounters | which turns it around and prints some more characters.

Labyrinth

In labyrinth, control flow is determined by the program's layout. All spaces and alphabetic characters are considered walls. The # command pushes the number of items on the stack, which is 0, to the stack. Then execution continues in the only possible direction, south. Here, the number of items on the stack is pushed again, this time pushing a 1. Now there's 2 directions to go: south again or east. Since the topmost value on the stack is positive, execution would try to go west, but that path is blocked, so it goes east instead. _ pushes a 0. Now there's again 2 directions to go, but we came from one direction and unless nothing else is possible, the IP will never flip around and go back the direction it came from, so we continue south. Here we have a (, which decrements the top of the stack. This means the topmost item is now -1. Excluding the direction we came from, there's 3 directions to go, but since the top of the stack is negative, we go east. Here we push 0 a bunch of times, which means we continue east for as long as possible. In the end, we go south because that's the only other place to go. There we find a ', which is a no-op if debugging output isn't enabled. Now, labyrinth treats tabs as a single space, so the character south of the ' is actually " from the start of the echo's parameters. Execution continues there. Below that, there is only one path to follow, which leads to the 4th character of line 9. There, we simply construct the ascii values corresponding to "elf" and print them.

Make

The first 3 lines are comments. The 4th line is somehow a valid target name. (To be honest, I have no idea either about why this works.) Since this is the first target in the makefile, it's what gets executed when no argument is given to make. The rule just prints the character count. Then we define a variable called N which contains the rest of the script. It ends on the 2nd-to-last line with the endef command. Following it is a comment that ends with a backslash. This causes make to interpret the next line as part of the comment too.

A Pear Tree

A Pear Tree starts execution by finding the longest substring of the program whose CRC32 is 0. Then it shifts the whole program so that said substring is at the start of the program. This long substring with a CRC32 of 0 is print"hezar";exit;<<'/*';#NJ@G@GMCI, which just happens to be valid Perl code. No, actually I used a tool called crchack to generate some letters to add to a comment so that the string's CRC is 0. So this Perl program is shifted to the very beginning of the program. It contains a print statement, an exit statement and a heredoc. The heredoc is terminated by the line that was right before the perl script originally, and thus is at the very end of the program now. So the heredoc skips the entire rest of the script and all of the syntax errors that would arise from not doing so.

randomdude999

Posted 2019-10-22T13:57:06.433

Reputation: 789

Better question would be why did I use 1000 instead of something like 800... i'll try to fit a few more in here – randomdude999 – 2019-10-23T06:44:58.723

2I hereby confirm that at least Dutch (Duizend) is accurately spelled. – Gloweye – 2019-10-23T09:59:00.660

For reference, I also know the estonian, english and swedish versions are accurate (being a fluent speaker of the first 2 (or well, fluent enough in the case of english) and having asked a swedish friend of mine). – randomdude999 – 2019-10-23T10:08:21.670

1"Tuhat" is also Finnish :) – Antti29 – 2019-10-23T11:53:25.357

But will it matter if the result is going to be 1k characters anyways? Or are you suggesting I change all of the strings to something like 800? (thanks for the suggestions anyways) – randomdude999 – 2019-10-23T12:53:56.623

@JoKing: That's a fair point, but I think I've exhausted all of the languages that I even barely know by this point. But if you know some that could fit in here, feel free to suggest them. – randomdude999 – 2019-10-23T13:00:28.857

@JoKing: Is using >o< to output the stack in ><> even valid? It'll print the error message (due to popping off an empty stack), is that allowed? – randomdude999 – 2019-10-23T16:07:07.617

This is really impressive. I tried both Python 2, Python 3, C, C++, Zsh and Bash. I can't get Make to work however: Makefile:5: *** missing separator. Stop.. I'm using GNU Make 4.2.1, built for x86_64-apple-darwin19.0.0. – grooveplex – 2019-10-24T15:53:29.563

@grooveplex: Are you sure you have a hard tab at the start of line 5? – randomdude999 – 2019-10-24T15:55:56.430

@randomdude999 Somehow the code snippet didn't have that. Changed it to a hard tab and it works perfectly! – grooveplex – 2019-10-24T16:15:59.120

@grooveplex: Yeah, stack exchange removes all hard tabs in posts. You could have copied it from TIO too, they work there. – randomdude999 – 2019-10-24T16:22:11.893

13

6 languages, prints 80

//'Ÿ¯"y"«q
   áttatíu/*
";"
åo 八
t?  十
t@   "
io    o
oo     @
"o
0o
1 K`ochenta

(There's also 5/90 solution with a different approach in the edit history if you're interested)

05AB1E/English - eighty

//'Ÿ¯"y"«q
//          # no-ops
  'Ÿ¯       # push dictionary string "eight"
     "y"    # push literal string "y"
        «   # concatenate
         q  # end program

Try It Online!

Once execution ends, the stack top (eighty) is implicitly printed, and nothing later on in the file will be considered at all.

ink/Íslenska - áttatíu

   áttatíu/*

Try It Online!

The very first line in the file is a comment, due to the //. The /* at the end of this line begins a multi-line comment (which we never have to close), so ink doesn't care about anything later on in the file either.

That just leaves the text áttatíu, which ink happily prints, because that is what ink does.

Alice/日本語 - 八十

/

  "
   八
    十
     "
      o
       @

Try It Online!

In Alice, / is a mirror, but unlike in other 2D languages you might be familiar with, they reflect you 135 degrees rather than 90. So after encountering the /, we move diagonally, encountering "八十" (which pushes the string 八十 onto the stack), o (which outputs it), and @ (which terminates the program).

><>/Norsk - åtti

//

";
åo
t?
t@
io
oo
"o
0o
1

Try It Online!

The / at the start deflects the instruction pointer upwards, after which it wraps around to the bottom, travelling up the first column.

It then pushes the numbers 1 and 0 and the characters oittin onto the stack, bounces around on the mirrors at the top, and travels up along the second column.

In the second column, we print the first four items on the stack (åtti). Then we shuffle the last three values around a bit using @, leaving the 0 at the top, which thanks to the ? makes us skip the final print instruction, before we arrive at the ; which ends the program.

Gol><>/Svenska - åttio

//

";
åo
t?
t@
io
oo
"o
0o
1

Try It Online!

Works just like ><> except the @ shuffles the stack values in a different way, so we end up not skipping the last print, thus printing åttio instead of åtti.

Retina/Español - ochenta

1 K`ochenta

Try It Online!

The first ten lines are presumably interpreted as replacement stages, but since we don't have any input to manage, we don't really care what they do. the last stage, however, is a constant stage - we can tell because the config string before the backtick has a K in it. That means we just discard any input that stage would get from the stages before it, and output ochenta.

Sara J

Posted 2019-10-22T13:57:06.433

Reputation: 2 576

2I like this answer best because it has the highest language to length ratio of all submissions so far. – 79037662 – 2019-10-22T20:08:03.970

1It doesn't save anything in this case of course (and maybe you've used the two double quotes on purpose to make the length 80), but just in case you didn't know, the "y" could be 'y in the 05AB1E portion of the program. 05AB1E has builtins for 1, 2, or 3 length strings or amount of dictionary words, being ', , respectively. – Kevin Cruijssen – 2019-10-23T09:56:50.757

10

3 Languages, 800 chars

  • PHP, Norwegian, Outputs ÅTTE HUNDRE
  • Emoji, Persian, Outputs هشتصد
  • COW, English, Outputs EIGHT HUNDRED
<?=['ÅTTE HUNDRE','⛽هشتصد➡','
MoO
MoO MoO
MoO MoO MoO
MoO MoO MoO MoO
MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MMM MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO Moo MoO MoO MoO MoO Moo MOo MOo
Moo MoO Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO Moo MMM Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO
Moo MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO Moo MOo MOo
MOo MOo MOo MOo MOo Moo MOo MOo MOo MOo MOo MOo MOo MOo MOo MOo Moo MMM
MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO MoO Moo MMM MoO Moo MOo Moo'][0];

PHP - Try it online!

COW - Try it online!

Emoji - Try it online!

Night2

Posted 2019-10-22T13:57:06.433

Reputation: 5 484

23 languages, 3 upvotes. Now it is broken. – None – 2019-10-23T15:16:12.607

9

3 8 9 languages, 300 characters

                            //®di.•paü¾p•ë"兩百"„„í°¡r\}qtrescientos➡\u000A\u002F\u002A
    //\
{{Write("trois cent"/*\u002A\u002Finterface M{static void main(String[]a){System.out.print("driehonderd"                                             /*
    #include<stdio.h>
 int main(){{puts(sizeof'a'<sizeof(int)?"trezentos":"dreihundert"/**/);}}//

Try it online in 05AB1E / Chinese - outputs 兩百.
Try it online in 05AB1E (legacy) / Italian - outputs trecento.
Try it online in 2sable / English - outputs three hundred.
Try it online in Java 8 / Dutch - outputs driehonderd.
Try it online in C# (Visual Interactive Compiler) / French - outputs trois cent.
Try it online in C / German - outputs dreihundert.
Try it online in C++ / Portuguese - outputs trezentos.
Try it online in Whitespace / Japanese - outputs 三百.
Try it online in Emoji / Spanish - outputs trescientos.

Explanation:

05AB1E / Chinese and 05AB1E (legacy) / Italian and 2sable / English:

                    # Spaces/tabs are no-ops
  //                # Divide twice (without input)
                    # Legacy 05AB1E / new 05AB1E: this pushes an empty string
                    # 2sable: the stack remains empty
    ®               # Push -1
     d              # Legacy 05AB1E: check if this -1 is an integer (truthy)
                    # New 05AB1E: check if this -1 is non-negative (≥0) (falsey)
                    # 2sable: check if this consists only of digits (falsey)
      i             # If it is truthy:
       .•paü¾p•     #  Push compressed string "trecento"
      ë             # Else:
       "兩百"       #  Push string "兩百"
       „„í°¡        #  Push dictionary string "one hundred"
             r      #  Reverse the stack
                    #   New 05AB1E: "","兩百","one hundred" → "one hundred","兩百",""
                    #   2sable: "兩百","one hundred" → "one hundred","兩百"
              \     #  Discard the top item
                    #   New 05AB1E: "one hundred","兩百","" → "one hundred","兩百"
                    #   2sable: "one hundred","兩百" → "one hundred"
      }             # Close the if-else
       q            # Terminate the program
                    # (after which the top of the stack is output implicitly as result)
                    # And any character after it are no-ops

See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why „„í°¡ is "one hundred" and .•paü¾p• is "trecento".

Emoji / Spanish:

                    # Some no-ops
trescientos    # Push string "trescientos"
                ➡  # Print the top to STDOUT
                    # Some more no-ops

Whitespace / Japanese:

Only spaces, tabs, and newlines are relevant for Whitespace programs and every other character is ignored. So the program is actually (S = space; T = tab; N = newline):

SSSTSSTTTSSSSSTSSTN
TN
SSSSSTTTSTTSSTTTTTTSN
TN
SS
  1. SSSTSSTTTSSSSSTSSTN push the integer 19977 to the stack (first S is to enable stack manipulation; second S is to push a number; third S is positive (T would have been negative); the S and T that follow are the integer in binary where S=0 and T=1; and the trailing N finishes this command.
  2. TNSS print this integer as character (with this unicode value) to STDOUT (first TN enables I/O; the following S is to output to STDOUT; and the second S to output as character (T would have been as integer)).
  3. SSSSSTTTSTTSSTTTTTTSN push 30334
  4. TNSS print as character again

C# (Visual Interactive Compiler) / French:

The first line contains some no-op spaces/tab, and a comment (// starts the comment, making everything after it on that same line no-ops).
The second line is similar, again a no-op tab and a comment.
The third line starts with {{Write("trois cent", and /* starts a (potentially multi-line) comment-block. This stops at the */ on the last line, making everything in between no-ops. After which );}} is part of the C# program again (and the very last // is a comment again, only there to make the program-size 300).

So the non-comment parts of the C# (Visual Interactive Compiler) program are:

{{Write("trois cent");}}

The {{ and }} are code-blocks, and basically no-ops in this case.
The Write("trois cent"); prints this text to STDOUT.

C / German and C++ / Portuguese:

First line is a comment again.
The //\ on the second line is relevant in C and C++, as it will comment out the entire next line. The #include<stdio.h> and int in front of the main-function are mandatory in C++ (and optional in C; it would run fine without these two parts, but would generate some warnings).
The /**/ and // are again comments.

So the non-comment parts of the C and C++ programs are:

#include<stdio.h>         // Required include for `puts` in C++
int main(){               // Mandatory main-function:
  {                       //  No-op code-block (similar as the C# part above)
    puts(                 //   Print to STDOUT with trailinb newline:
      sizeof'a'           //    If the byte-size of character 'a' 
      <                   //    is smaller than
      sizeof(int)?        //    the byte-size of an integer:
       "trezentos"        //     Print "trezentos"
      :                   //    Else:
       "dreihundert");}}  //     Print "dreihundert"

In C (and Java), values of type char are saved as an integer. sizeof(int) and sizeof'a' will therefore both result in 4 in C, and 4<4 is falsey, so "dreihundert" is printed. In C++ (and C#), values of type char are actually a separated type saved as characters. sizeof'a' will therefore result in 1 in C++, and 1<4 is truthy, so "trezentos" is printed.

Java 8 / Dutch:

In Java, we can use \uHEX as unicode values, which are read as characters after compilation. The very first line therefore compiles to (I'll ignore the leading spaces/tabs for now to make it a bit more compact):

//®di.•paü¾p•ë"兩百"„„í°¡r\}qtrescientos➡
/*

The \u000A\u002F\u002A are a newline, / and * respectively. Just like in the C# program, this will stop at the first */, which is the \u002A\u002 on the third line in this case. There the Java program starts:

interface M{static void main(String[]a){System.out.print("driehonderd"

After that come a bunch of no-op spaces/tabs again, followed by another /* which stops at the same place as the C# program. So the full Java program is:

interface M{static void main(String[]a){System.out.print("driehonderd");}}

interface M{                    // Class:
  static void main(String[]a){  //  Mandatory main method
    System.out.print(           //   Print to STDOUT
      "driehonderd");}}         //    The string "driehonderd"

Why these languages?

Natural languages:

  • I'm fluent in English and Dutch
  • I've learned French and German at high school
  • I watch quite a lot of Japanese anime
  • I know a few loose words in Spanish, Italian, and Portuguese
  • Chinese was short enough to fit after adding 2sable ;)

Programming languages:

  • I'm pretty skilled at Java, 05AB1E, C#, and Whitespace
  • I've used the polyglot tricks for combining Java & C as well as Java & C# before here and here
  • I've seen the C / C++ difference before, and it was therefore easy to add here
  • Emoji is a perfect language to add, since it ignores everything except for the relevant emoji commands (unlike Emojicode I tried to add as well..)
  • 2sable is based on an old version of 05AB1E (legacy), and therefore rather similar as 05AB1E and 05AB1E (legacy), except it's a bit older than both.

I might try to learn and add Aheui for a suiting Korean output later on, since it will ignore everything except for the Korean characters in the code.

Kevin Cruijssen

Posted 2019-10-22T13:57:06.433

Reputation: 67 575

Nice answer. I hope that, after Whitespace, we (the code golf community) can go out on a bender and add some off the wall natural language to the mix. Romansh, anybody? – Andrew – 2019-10-22T14:55:07.407

I do wish that there is a Romansh translator. – None – 2019-10-24T09:26:28.883

3

3 4 languages, outputs 20

This answer is inspired by this answer. Let's see whether I can fit in the 4th 5th language in 20 characters.

(廿)"二十""hai"tyve➡S

Try it online in Actually!

Try it online in 05AB1E!

Try it online in Emoji!

Try it online in Underload!

Explanation

Actually:

(                           Roll empty stack left
 廿                         Unidentified instruction
   )                        Roll empty stack right
    "二十""hai"             Push 2 strings
               t         Pop a, b, push a[b:]. Nothing special since b is a string.
                   y        Push prime factors of the string on the top of the stack
                    v      Discard TOS for the seed of the RNG
                     e     Push exp(Top Stack String)
                      ➡S Sort the Top Of Stack; no effect to the text

Outputs the whole stack implicitly.

05AB1E:

(                           Negate the empty stack
 廿                         Unidentified instruction
   )                        AFAICT this is a NOP
    "二十""hai"             Push 2 strings onto the stack
              t           Square root top of the stack string
                  y         Push string variable
                   v        Enumerated loop
                    e       Number of permutations
                     ➡S Cast to list of characters / digits.

This outputs the TOS implicitly.

Emoji:

(廿)"二十""hai"             No operations
              tyve➡  Output tyve
                          S NOPs

Underload:

(廿)                         Push 廿 onto the stack
    "二十""h                 NOPs
            a                Enclose TOS with braces
             i"tyve➡  NOPs
                           S Output TOS
```

user85052

Posted 2019-10-22T13:57:06.433

Reputation: