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 b
th 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 print
s 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.
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.460I was asking about the output, RE: '''One of your outputs MUST be
"true"
and"false"
.''' – Jonathan Allan – 2016-11-26T13:14:11.4231@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