Multi-lingual Challenge

12

1

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.

steenbergh

Posted 2016-11-26T11:36:58.033

Reputation: 7 772

Is it intentional that your program can just check the version of the interpeter/compiler its run with? – CodenameLambda – 2016-11-26T11:42:53.733

@CodingLambdas I'm not sure I get what you're saying? – steenbergh – 2016-11-26T11:43:53.547

Example with python: import sys; is_py3 = sys.version_info.major == 3. – CodenameLambda – 2016-11-26T11:56:01.430

@CodingLambdas Yes; "Different versions of programming languages count as different languages". – steenbergh – 2016-11-26T11:57:44.913

1Are "True" and "False" acceptable in place of the required "true" and "false"? – Jonathan Allan – 2016-11-26T12:44:25.460

I was asking about the output, RE: '''One of your outputs MUST be "true" and "false".''' – Jonathan Allan – 2016-11-26T13:14:11.423

1@JonathanAllan My bad. Yes, that's fine for output. – steenbergh – 2016-11-26T13:31:32.030

3I'd love to see an esolang where the output is 3D-printed and mailed back to you. – ETHproductions – 2016-11-26T15:02:29.190

2This is too broad for a popularity contest. Do X creatively pop cons have fallen out of scope. – Dennis – 2016-11-26T19:19:05.790

@Dennis added win-condition. – steenbergh – 2016-11-26T20:06:56.430

If someone manages all the dialects for Chinese... – clismique – 2016-11-29T11:09:15.137

Answers

5

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.

Adám

Posted 2016-11-26T11:36:58.033

Reputation: 37 779

Very nice answer! And great proof on extensibility. – steenbergh – 2016-11-30T08:48:23.410

I count 243 bytes. – Conor O'Brien – 2016-12-07T22:36:53.367

@ConorO'Brien Fixed. Thanks. – Adám – 2016-12-08T08:30:18.337

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. – RedClover – 2018-01-13T14:30:10.000

11

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

Lynn

Posted 2016-11-26T11:36:58.033

Reputation: 55 648

1False in Danish is falsk. – Adám – 2016-11-29T08:02:18.257

I'd give you two upvotes for that print statement! – steenbergh – 2016-11-30T08:53:41.933

10

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.

James Holderness

Posted 2016-11-26T11:36:58.033

Reputation: 8 298

An explanation would be helpful – user41805 – 2016-11-27T18:08:51.943

1Very nice answer; using all different versions of the same language really makes this subtle. – steenbergh – 2016-11-30T08:50:55.200

5

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.

Dom Hastings

Posted 2016-11-26T11:36:58.033

Reputation: 16 415

3

Pyth, Python - 28 bytes

#>"onwaar"yQ.q
print input()

Maltysen

Posted 2016-11-26T11:36:58.033

Reputation: 25 023

You can save a byte by getting rid of .q and adding a ;at the end. – TheBikingViking – 2016-11-26T20:55:34.113

@TheBikingViking I don't think so, that would make it an infinite loop. – Maltysen – 2016-11-26T20:57:31.770

Test – TheBikingViking – 2016-11-26T20:58:36.223

3

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

Pete Arden

Posted 2016-11-26T11:36:58.033

Reputation: 1 151

2

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.

Erik the Outgolfer

Posted 2016-11-26T11:36:58.033

Reputation: 38 134

1

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

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

user41805

Posted 2016-11-26T11:36:58.033

Reputation: 16 320

For the BF version, shouldn't it output u conditionally, not s? – HyperNeutrino – 2016-11-27T20:40:21.040

@AlexL. It does output u conditionally – user41805 – 2016-11-28T07:30:03.067

Oh. I got confused because the explanation says that it outputs s conditionally; could you fix that for clarity? Nice answer anyway. – HyperNeutrino – 2016-11-28T13:08:36.247

If input is empty (ie false), output `s`. I think that is the part which got Alex L. confused. – Erik the Outgolfer – 2016-11-28T14:08:11.510

@AlexL. I noticed the mistake, I edited it now! – user41805 – 2016-11-28T15:52:22.213

1

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.

IDid

Posted 2016-11-26T11:36:58.033

Reputation: 101