After all the fun we've had with polyglot challenges in the (recent) past, how about a challenge where the output can be in two languages?

Your answer needs to accept boolean input b and output the text "true" or "false". The same code needs to output, when run in another language, "waar" or "onwaar" or any other translation of trueand false.

Input

  • Input is a clearly distinguishable truthy/falsey. Admissible are the actual values T/F, a bit, int or (empty) string.
  • Input needs to be the same for all parts of your submission.

Output

  • Output may be returned by a function, written to STDOUT, placed in a popup-window, 3D-printed and mailed etc.

  • The output needs to represent the state of b. So a 'truthy' needs to output 'true', 'waar' ... and 'falsey' should lead to 'false', 'onwaar', etc.

  • Different languages may use different output methods.

Languages used

  • One of your outputs MUST be "true" and "false".

  • Different versions of programming languages count as different languages for this challenge.

  • Different dialects of a human language count as different languages for this challenge.

  • You may extend the polyglot to more than two programming languages. Every programming language needs to output a distinct human language.

The answer with the most languages incorporated will be declared the winner. When tied, bytecount is considered.

  • Is it intentional that your program can just check the version of the interpeter/compiler its run with? – CodenameLambda Nov 26 '16 at 11:42
  • @CodingLambdas I'm not sure I get what you're saying? – steenbergh Nov 26 '16 at 11:43
  • 1
    @JonathanAllan My bad. Yes, that's fine for output. – steenbergh Nov 26 '16 at 13:31
  • 2
    I'd love to see an esolang where the output is 3D-printed and mailed back to you. – ETHproductions Nov 26 '16 at 15:02
  • 1
    This is too broad for a popularity contest. Do X creatively pop cons have fallen out of scope. – Dennis Nov 26 '16 at 19:19
up vote 4 down vote accepted

Dyalog APL, 243 237 bytes: 14 languages, extendable to 131*

-6 bytes thanks to Soaku.

Requires ⎕IO←0 which is default on many systems. Prompts for input of 0 or 1.

((⎕AV⍳'ëáàÆÅÄòðÓÈÇ')⍳⍎⎕D∩⍨4↑1⊃#⎕WG'APLVersion')⊃⎕⊃s¨⌽(s←{1↓¨⍵⊂⍨⍵=⊃⍵})';,true,adevarat,haqiqiy,otito,tunay,bener,prawda,dogru,vrai,that,wahr,vero,verdade,cierto;,false,fals,yolg''on,eke,mali,palsu,falsz,yanlis,faux,sai,falsch',18⍴',falso'

Depending on version (9.0 through 16.0, with minor versions) it outputs in English, Spanish, Portuguese, German, Vietnamese, French, Turkish, Italian, Polish, Sundanese, Filipino, Yoruba, Uzbek, or Romanian, although without diacritics.

⎕AV⍳'ëáàÆÅÄòðÓÈÇ' in the indices of the Atomic Vector (151 142 141 133 132 131 122 121 111 102 101 96)

((...)⍳...) find the position of

the evaluated

⎕D∩⍨ intersection of Digits and

4↑ the four* first characters of

1⊃ the second element of

#⎕WG'APLVersion' the version number

(...)⊃ then use that to pick among

⎕⊃ the input'th (0: first; 1: second) element of

the function s (which we will define shortly) applied to each of

the reverse of

(s←{...}) s applied to – where s is defined as

1↓¨ the first character dropped from each of

⍵⊂⍨ the argument partitioned where

⍵= the characters of the argument are equal to

⊃⍵ the argument's first character

';,true,adevarat,...,falsch', this string prepended to

18⍴',falso' eighteen characters taken cyclically from that string

* Since version 12.1, the version number includes build number, so by increasing the number of characters taken from this string, it is easy to cover all 131 Latin script languages.

  • Very nice answer! And great proof on extensibility. – steenbergh Nov 30 '16 at 8:48
  • I count 243 bytes. – Conor O'Brien Dec 7 '16 at 22:36
  • @ConorO'Brien Fixed. Thanks. – Adám Dec 8 '16 at 8:30
  • I know it's late, but you can save few bytes by replacing prawdziwy to prawda and falszywy to falsz. The shorter forms fit better here and give you a better score. – Soaku Jan 13 at 14:30
  • @Soaku Thanks. Done. – Adám Jan 13 at 20:29

6 languages, 169 bytes

Expects 0\n or 1\n as input, and prints words in:

  • Python 2 (Dutch vals/waar),
  • Python 3 (French faux/vrai),
  • Ruby (English false/true),
  • CJam (Norwegian usant/sant),
  • Golfscript (Danish usand/sand),
  • Befunge-93 (Italian falso/vero).

"#{puts gets>?1;exit}"" "#"& 1v
""
print('vwfvaaarlauasrxi'[int(1/2*4+int(input()))::4])
""#";;;;ri"u">"sant"+o
""""
__END__
]0=~"u">"sand"""#@,,,,"vero"  _"oslaf",,,,,@
  • 1
    False in Danish is falsk. – Adám Nov 29 '16 at 8:02
  • I'd give you two upvotes for that print statement! – steenbergh Nov 30 '16 at 8:53

All the Funges, 6 languages, 146 bytes

💥 Now in 3D! 💥

A vv"faux"0"vrai"mv#<v&#;9*j"kslaf"6j"etke">:#,_@;
; >"otreic"0"oslaf"v^<
&^>"murev"0"muslaf">
&^&<"false"0"true"<
>_>:#,_@
^_^

For clarity I've separated the two planes of code so you can see how they're layered. On disk these two blocks would be separated with a form feed character at the end of the line above.

   h"vals"0"waar"<

The rules did say different versions of a language count as separate languages, so this one is six versions of Funge/Befunge. :)

Thanks to Dennis, all of the Befunge versions can now be tested online at TIO. There aren't currently working implementations of the Unefunge and Trefunge variants, though, so for those I'd recommend Rc/Funge.

A is ignored in Befunge 93 and 96, but is the About Face command in 97 and is unsupported in 98 and thus reflects. This means that 93 and 96 follow the v downwards while 97 and 98 wrap around to the opposite side of the playfield.

In Befunge 96 a ; followed by space at the start of the line marks it as a comment, so that line is skipped and the interpreter continues to the > on the third line. In 93, though, the interpreter follows the > on the second line.

The 97/98 path continues on the first line from right to left, skipping over the section inside the ; comment markers, bridges the & command, eventually reaching the U-bend sequence v<^<. In Unefunge, these direction changes aren't supported so the interpreter reverses direction and executes the previously skipped section in the comments. In Befunge/Trefunge it continues to the left.

In Befunge 97 the m command is unsupported and thus skipped, so the interpreter continues along the first line. In 98 it's 3D-only so it reflects in Befunge (2D) and the interpreter follows the v to the right of it down to the fourth line. In Trefunge (3D) it's a High-Low branch which transfers up a level along the z-axis to the second plane.

So other than the Unefunge case, we have each version gathering their string pair from a separate line before being directed to one of the & commands to get the user input. Those code paths then all merge together via the ^ commands in the second column, directing the program flow upwards through the top of the playfield, wrapping around to the bottom again.

Finally we have the ^_^ sequence which decides which path to follow based on the user input. If 0, we go straight to the output sequence (>:#,_) writing out the false string. If 1, we first execute >_ which clears the first string off the stack, and thus output the true string.

  • An explanation would be helpful – Cows quack Nov 27 '16 at 18:08
  • Very nice answer; using all different versions of the same language really makes this subtle. – steenbergh Nov 30 '16 at 8:50

5 languages, 249 bytes

Note: the \r and \e are literal line-feed and escape characters, but \x5b has to be as-is otherwise Ruby complains about the character class in the regex.

A bit late to the party, and not a winner by any means, but I started working on a polyglot for the thanksgiving challenge and felt it might be a bit late so transformed it into this!

q=0//1;'''<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord;def input()gets.to_i;end;q=+q+0;True="Vrai";False="Faux";'+;sub a{<><1?Vals:Waar}q-
input=prompt;print=alert;True="Vero";False="Falso"//'#'''
a=[False,True];b=input();1-+1;print(a[b])

Explanation

Python: True / False

q=0//1;'''<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord;def input()gets.to_i;end;q=+q+0;True="Vrai";False="Faux";'+;sub a{<><1?Vals:Waar}q-
input=prompt;print=alert;True="Vero";False="Falso"//'#'''
a=[False,True];b=input();1-+1;print(a[b])

Here we set q to 0//1 which is 0, then we have a ''' string that contains most of the other code, store an array containing False and True and indicies 0 and 1 respectively, assign the input to b (which should be 0 or 1 to signify Falsy and Truthy) then print the bth index of a, showing False or True.


Ruby: Vrai / Faux

q=0//1;'''<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord;def input()gets.to_i;end;q=+q+0;True="Vrai";False="Faux";'+;sub a{<><1?Vals:Waar}q-
input=prompt;print=alert;True="Vero";False="Falso"//'#'''
a=[False,True];b=input();1-+1;print(a[b])

As with the Python script, we set the variable q, but in Ruby this is set to 0 / /1;'''<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord, as Ruby breaks this down as 0/ as "zero divided-by" and the following / as "beginning of regex literal". Using this literal I'm able to conceal the PHP code and begin Python's '''. We have to add .to_s.ord because the right operand to / has to be a Fixnum. After this we define a function input() and the variable True and False to contain their French counterparts and finally start a string ' which continues onto the next line. Finally we create an array a which contains "Vrai" and "Faux" and select them using the input()ed number 0 or 1.


Perl: Waar / Vals

'0//1;\'\'\'<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord;def input()gets.to_i;end;q}+q{0;True="Vrai";False="Faux";\'';sub a{<><1?Vals:Waar}'
input=prompt;print=alert;True="Vero";False="Falso"//\'#\'\'\'
a=[False,True];b=input();1'+1;print(a[b])

In Perl, the q=..=, q+...+ and q-...- blocks are quoted literals using unusual delimiters, in the code above I've replaced these with '...'. Most of the code is contained in a literal string, but we do define sub a (which contains a <><!) that checks if STDIN is less than 1, returning either Waar or Vals. The print(a[b]) actually prints the result of calling the sub a with and argument of [b] which is an ArrayRef that contains the bare-word b.


JavaScript: Vero / Falso

q=0//1;'''<?die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));?>/.to_s.ord;def input()gets.to_i;end;q=+q+0;True="Vrai";False="Faux";'+;sub a{<><1?Vals:Waar}q-
input=prompt;print=alert;True="Vero";False="Falso"//'#'''
a=[False,True];b=input();1-+1;print(a[b])

The first line is mostly commented out by the division 0//1 (// is line comment in JavaScript) so we just set q to 0. The next line deals with mapping the JS functions to their Python names and setting variables True and False to be the Italian strings, finally we execute the same as the Ruby code, setting a to an array of the Italian words and selecting using an input of 0 or 1.


PHP: Ekte / Falsk

die("\r\e\x5bK".(fgetc(STDIN)?Ekte:Falsk));

Since PHP only executes code between <?...?> everything else is output as-is, so our code here simply prints a line-feed (to put us back to the beginning of the current line) and the ANSI escape sequence to clear to the end of the current line, followed by either Ekte or Falsk depending on whether the input char (0 or 1) is truthy or falsy.

Pyth, Python - 28 bytes

#>"onwaar"yQ.q
print input()
  • You can save a byte by getting rid of .q and adding a ;at the end. – TheBikingViking Nov 26 '16 at 20:55
  • @TheBikingViking I don't think so, that would make it an infinite loop. – Maltysen Nov 26 '16 at 20:57
  • Test – TheBikingViking Nov 26 '16 at 20:58

2 languages, 60 bytes

print('onwaar'[2*int(input()):]);1#¶ị“¡ẈẆ“⁸1»

Languages are:

  • Jelly true false
  • Python3 waar onwaar

Note: There are UTF-8 bytes, not Jelly bytes.

C#, Java, 104 Bytes

Golfed:

String M(Boolean b){String s=b+"";if(s=="True")return "Wahr";if(s=="False")return "Falsch";return b+"";}

Ungolfed:

  class MultiLingualChallenge
  {
    public String M(Boolean b)
    {
      String s = b + "";
      if (s == "True")
        return "Wahr";
      if (s == "False")
        return "Falsch";
      return b + "";
    }
  }

Test:

C#

Console.WriteLine(new MultiLingualChallenge().M(true));
//Wahr
Console.WriteLine(new MultiLingualChallenge().M(false));
//Falsch

Java

System.out.println(new MultiLingualChallenge().M(true));
//true
System.out.println(new MultiLingualChallenge().M(false));
//false

Explanation:

When calling ToString() or toString() on a Boolean in C# and Java respectively, C# prints the string with a capital first letter, True and False, but Java prints all in lower case true and false.

Console.WriteLine(true+"");
//True

System.out.println(true+"");
//true

Lua/JavaScript, 68 bytes

x=1//1print(...and"true"or"false")
--x;alert(prompt()?"vrai":"faux")

Don't know why I golfed it; I just felt like it.

JavaScript / BF

In both these languages, no input is considered as false and any input is considered true.

When you see the structure of the program rotated 90 degrees to the left, the BF symbols look like towers in a city :)

Try it online (BF true testcase)!

Try it online (BF false testcase)!

console.log(prompt()?"true":"false")
/*
           >,[>
+          <<]>>[->-<]
+          >[<->[-]]<>[-]<[>>
+++        [->
++++       <]>[->
++++++++++ <]>---.>]>
++++++++++ [->
++++++++++ <]
+++        [->
+++++      <]>.<
++++       [->----<]>--.<
+++        [->
++++       <]>
+          .<
+++        [->---<]>-.
*/

Explanation

JavaScript

If the prompt is true (ie not empty because prompt returns a string), outputs true, or else outputs false.

BF

Outputs sand (Danish for true) if there is an input, or else outputs usand (false) if the input is empty.

TL;DR If input is not empty (ie true), don't output anything. If input is empty (ie false), output u. Then, regardless whether the input is true or false, output sand.

I have taken inspiration from https://esolangs.org/wiki/Brainfuck_algorithms with which I constructed the logic of my program.

Take input. If input is not empty, increment memory, let's call this cell "Cell A". End if-statement

>
,[
>+
<<
]>

Compares the value of "Cell A" with 0. If they are equal, let "Cell B" be 1, or else let it be 0.

>
[->-<]+>[<->[-]]<

If "Cell B" is 1, then output u. Close if-statement

>[-]<
x[>>
+++[->++++<]>[->++++++++++<]>---.
>]

Output sand

>
++++++++++[->++++++++++<]+++[->+++++<]>.
<++++[->----<]>--.
<+++[->++++<]>+.
<+++[->---<]>-.
  • For the BF version, shouldn't it output u conditionally, not s? – HyperNeutrino Nov 27 '16 at 20:40
  • @AlexL. It does output u conditionally – Cows quack Nov 28 '16 at 7:30
  • Oh. I got confused because the explanation says that it outputs s conditionally; could you fix that for clarity? Nice answer anyway. – HyperNeutrino Nov 28 '16 at 13:08
  • If input is empty (ie false), output `s`. I think that is the part which got Alex L. confused. – Erik the Outgolfer Nov 28 '16 at 14:08
  • @AlexL. I noticed the mistake, I edited it now! – Cows quack Nov 28 '16 at 15:52

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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