40
\$\begingroup\$

Thanksgiving in the United States is coming up on November 24th. Many people will have a large dinner with their families, traditionally including turkey and many side dishes. This typically means the family members must coordinate who's going to bring each of the various dishes. In this challenge, the goal is to write a polyglot that outputs a different dish in each language it's run in.

Menu

(Selected from Wikipedia. In case it's not obvious, each line is one item.)

turkey
stuffing
dressing
cranberry sauce
mashed potatoes
gravy
winter squash
sweet potatoes
corn
green beans
green bean casserole
mac and cheese
macaroni and cheese
salad
rolls
biscuits
corn bread
pumpkin pie
apple pie
mincemeat pie
sweet potato pie
pecan pie
apple cider
sweet tea

Rules

  • Each submission must run in at least 3 languages, each of which must output a different item from the menu. You may not use multiple versions of the same language (e.g. Python 2 and Python 3 cannot be used in the same answer).
  • Each entry must have the same bytes in each language's encoding. For example, ɱ is byte 0x1D in Jelly's encoding, which corresponds to ¢ in 05AB1E's encoding.
  • Different languages may use different output methods, but entries must be full programs in all languages, and follow one of our default allowed IO methods.
  • No programs may take input, but any of the programs may print to STDERR or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.
  • Case and whitespace do not matter. For example, an output of GreenbeAN S would still count as green beans.
  • As the central dish of every1 American Thanksgiving meal is turkey, one language must output turkey (ignoring case and whitespace).

Scoring

The submission that produces unique valid outputs in the most languages wins. In case of a tie, the shortest of the tied entries in bytes wins.

1. Yes, turkey is not the only main dish, but we're going to pretend it is.

\$\endgroup\$
  • 1
    \$\begingroup\$ Two related challenges: 1, 2 \$\endgroup\$ – ETHproductions Nov 19 '16 at 16:47
  • \$\begingroup\$ Case and whitespace do not matter So can we remove whitespace? Say output cornbread \$\endgroup\$ – Luis Mendo Nov 19 '16 at 17:20
  • \$\begingroup\$ @LuisMendo Yup. \$\endgroup\$ – ETHproductions Nov 19 '16 at 17:23
  • 1
    \$\begingroup\$ Well, I'll bring nothing, because I don't live in USA. XD \$\endgroup\$ – Mega Man Nov 20 '16 at 10:57
  • 1
    \$\begingroup\$ @ConorO'Brien I'll allow the null char as whitespace. And yes, you may use different "dialects" of BF. \$\endgroup\$ – ETHproductions Nov 21 '16 at 0:11

15 Answers 15

32
\$\begingroup\$

Pyke, Pyth, Python 2, Foo, Brain****, GolfScript, Actually, <><, Gol<><, Seriously, Befunge, Fission, Haystack, 13 languages, 546 bytes

When I saw the other 10 11 12 language answer, I had to add an extra one two 3. I'm also seriously considering dropping Pyth if only to save on bytes. (at the moment 162 of them)

#\ s[\g\r\a\v\y)w.q)\r\o\l\l\ssp00/;oooooooo'stuffing;oooooo~'`turkey'
print'corn'#))))))))))))))))))))))))]+[--------->++<]>+w.q++[->+++<]>++w.q+++++++++++w.q-----------w.q----------------;))!+f'!n'!i'!s'!s'!e'!r'!d'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))L
'bread'#)))\é'i'n'o'r'a+++++))))))))))))))))))))))))))))))))))))))))))))))))\♀1X'c'a'm++++'e's'e'e'h'c'd'n'a++++++++)+.&\�0\ó))))))))))))))))))
#\25*8*0+c25*6*9+c25*6*7+c25*6*5+c25*7*8+c25*8*0+c25*7*3+c25*6*9+c|000000
# ,,,,,,,,@0>00000000\#"biscuits"aetteews"

Pyke: Try it here! rolls

Relevent line of code:

#s[\g\r\a  \v\y)w.q)\r\o\l\l\ssp00/;oooooooo'stuffing;oooooo~'`turkey'

#s[\g\r\a  \v\y)w.q) - effectively a comment because # doesn't do anything with an empty stack
\r\o\l\l\ss - sum("r", "o", "l", "l", "s")
p - print(^)
00/ - raise a ZeroDivisionError to stop running code

Pyth: Try it here! gravy

Relevent line of code:

#s[\g\r\a  \v\y)w.q)\r\o\l\l\ssp00/;oooooooo'stuffing;oooooo~'`turkey'

#...) - while True:
s[\g\r\a  \v\y) - sum(["g", "r", "a", "v", "y"])
w - input()
.q - quit

All the )'s are for Pyth to make it compile without erroring on no input.


Python 2: corn

Line 1 is a whole comment

Line 2 prints "corn" and then has a comment

Line 3 has a string literal and then a comment

Line 4 onwards are comments


Foo: Try It Online! biscuits

Foo prints out anything enclosed in double quotes ("). In this case I was careful to only include languages that could cope with other forms of string input (Special case for Befunge). If there was any text after the final ", that would be printed too.


Brain****: Try It Online! salad

I copied the output of constant string generator. I had to escape all . characters with .q so it would play with Pyth and w. so it would play with Pyke. I added some extra - characters so the cells would get to the right points before printing at another . character in the 3rd line


GolfScript: Try It Online! cornbread

In GolfScript, # is a comment until end of line.

What GolfScript interpreter sees:

#comment
print'corn'#comment
'bread'#comment

In GolfScript, for whatever reason, print takes a string and prints it without a newline. Just having bread is enough to print it as well.


Actually: Try It Online! macandcheese

Relevant line:

'bread'#)))\é'i'n'o'r'a+++++))))))))))))))))))))))))))))))))))))))))))))))))\♀1X'c'a'm++++'e's'e'e'h'c'd'n'a++++++++)+.&\�0\ó))))))))))))))))))

é - clears the stack of whatever junk was on it before.
'i'n'o'r'a+++++ - create string "aroni"
) - rotate entire stack (effectively comments as stack is only 1 long)
♀1X - pop stack (now empty)
'c'a'm++++ - constructs the string "mac"
'e's'e'e'h'c'd'n'a++++++++ - constructs the string "andcheese"
) - rotate stack (reverse)
+ - "mac" + "andcheese"
� - quit

<><: Copy+Paste only turkey Animation of output


Gol<><: Try It Online! stuffing

As <>< except ` skips the first ' and only outputs enough characters to print stuffing


Seriously: Try It Online! macaroniandcheese

Relevant line:

'bread'#)))\é'i'n'o'r'a+++++))))))))))))))))))))))))))))))))))))))))))))))))\♀1X'c'a'm++++'e's'e'e'h'c'd'n'a++++++++)+.&\�0\ó))))))))))))))))))
é - clears the stack of whatever junk was on it before.
'i'n'o'r'a+++++ - create string "aroni"
) - rotate entire stack (effectively comments as stack is only 1 long)
♀1X - no-op
'c'a'm++++ - constructs the string "mac" + "aroni"
'e's'e'e'h'c'd'n'a++++++++ - constructs the string "andcheese"
) - rotate stack (reverse)
+ - "macaroni" + "andcheese"
. - print stack
0\ó - exit

Befunge: Try It Online! sweettea

Code that is looked at

#s[\g\r\a  \v - |
            ) - | - Directing the stack pointer to the correct place
            é - |
# ,,,,,,,,@0>00000000\#"biscuits"aetteews"

            >                              - change direction of travel
             00000000\#"biscuits           - a load of no-ops `#` skips the opening `"`
                                "aetteews" - add the chars to the stack in reverse order
  ,,,,,,,,@                                - output 8 chars from the stack and exit.

Fission: Try It Online! dressing

Code looked at:

;))!+f'!n'!i'!s'!s'!e'!r'!d'))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))L

Of which are used:

;!+f'!n'!i'!s'!s'!e'!r'!d'L
                          L - start an atom going left
                      !d'   - create the character `d` and print it
                              ...
;                           - exit

Haystack (2015): PECANPIE (with EXTRA newlines!)

#\
 r
 b
 \25*8*0+c25*6*9+c25*6*7+c25*6*5+c25*7*8+c25*8*0+c25*7*3+c25*6*9+c

Of which do something functional:

  25*8*0+c25*6*9+c25*6*7+c25*6*5+c25*7*8+c25*8*0+c25*7*3+c25*6*9+c

I construct each upper case ascii codepoint for the letters in PECANPIE in uppercase because they're all below 100. I then print them all out as characters.

\$\endgroup\$
  • 1
    \$\begingroup\$ Wow! Never seen a Pyth/Python polyglot (I guess comments make it easier) \$\endgroup\$ – Esolanging Fruit Nov 19 '16 at 18:10
  • \$\begingroup\$ You can remove some spaces and probably make it shorter (macaroni and cheese can be output as macaroniandcheese) \$\endgroup\$ – Artyer Nov 19 '16 at 18:26
  • \$\begingroup\$ @Artyer spaces removed \$\endgroup\$ – Blue Nov 19 '16 at 18:53
  • 1
    \$\begingroup\$ @Artyer this ain't no codegolf \$\endgroup\$ – FlipTack Nov 19 '16 at 22:41
  • 1
    \$\begingroup\$ Wait, GolfScript outputs cornrolls? That wasn't on the menu... \$\endgroup\$ – ETHproductions Nov 21 '16 at 15:50
10
\$\begingroup\$

CJam, 05AB1E, Dip, V, 4 languages, 36 34 bytes

2 bytes saved thanks to @DrMcMoylex!

"turkey"e#"corn"??"gravy"p&Ssalad

Original 36 byte code:

"turkey"e#"corn"??"gravy"p&ddisalad

After the & and before the d there is an <ESC>, which is 1 byte. So the code with the zero-width characters revealed looks like this:

"turkey"e#"corn"??"gravy"p&Ssalad

CJam

(<ESC> is not shown)

"turkey"e#"corn"??"gravy"p&Ssalad
"turkey"                           e# push this string
        e#"corn"??"gravy"p&Ssalad  e# comment
                                   e# implicit output

Try it online! outputs turkey

05AB1E

(<ESC> is not shown)

"turkey"e#"corn"??"gravy"p&Ssalad
"turkey"                           # push this string
                                   # STACK: ["turkey"]
        e                          # calculates nPr for the last two values in the stack
                                   # since there is only one value, this evaluates to nothing
                                   # as a result, "turkey" is popped
                                   # STACK: []
         #                         # if true end, since this is false, the program doesn't end
          "corn"?                  # push this string and print it without newlines
                                   # STACK: []
                 ?                 # prints nothing, since there is nothing in stack
                  "gravy"p&Ssalad  # nothing happens here since the stack is already printed using a command and there is NO implicit print now, I think

Try it online! outputs: corn

V

(<ESC> is shown)

"turkey"e#"corn"??"gravy"p&<ESC>Ssalad
"turkey"e#"corn"??"gravy"p&             Code that writes a newline followed by `rn"??"gravy"p&Ssalad`
                           <ESC>        Enters normal mode
                                S       Deletes line and enters insert mode
                                 salad  Writes salad

Try it online! outputs a newline followed by salad

Dip

(<ESC> is not shown)

"turkey"e#"corn"??"gravy"p&Ssalad
"turkey"                           push this string
                                   STACK: ["turkey"]
        e                          not in the language's database
         #                         push str("turkey") --> "turkey"
                                   STACK: ["turkey"]
          "corn"                   push this string
                                   STACK: ["turkey","corn"]
                ?                  pop "corn", if it is the boolean True (which it isn't) execute the following,
                                   but since it is false, nothing until the next ? gets executed
                                   STACK: ["turkey"]
                 ?                 if-statement end
                                   STACK: ["turkey"]
                  "gravy"          push this string
                                   STACK: ["turkey","gravy"]
                         p&        print turkey and end program
                           Ssalad  irrelevant since program has ended

Outputs gravy

Note: You cannot run python3 dip.py and then type in code for this due to the Escape character literal. It appears as ^[, which makes the Dip interpreter get confused and it thinks that [ is a command, and it results in an error.

The best way to run this is to edit the source file, change the last line in dip.py

main(input(">>> "), stack.Stack())

to

main("\"turkey\"e#\"corn\"??\"gravy\"p&Ssalad", stack.Stack())
exit()

Be sure to include the escape character literal!. Now the code as it is is passed into the interpreter so that it can understand it (" have to be escaped like \" so). Now if you run it from the command-line, it interprets the actual code and outputs gravy.

\$\endgroup\$
  • \$\begingroup\$ @ETHproductions I did not see that, anyways working on it... \$\endgroup\$ – Kritixi Lithos Nov 19 '16 at 18:44
  • \$\begingroup\$ @ETHproductions Done! Now it works in three languages! \$\endgroup\$ – Kritixi Lithos Nov 19 '16 at 19:00
  • \$\begingroup\$ Cool, nice one! \$\endgroup\$ – ETHproductions Nov 19 '16 at 19:07
  • 3
    \$\begingroup\$ +1 for pop "corn" in the explanation \$\endgroup\$ – FlipTack Nov 20 '16 at 10:58
  • \$\begingroup\$ A nitpick and a golfing tip: it's called "normal mode" not escape mode, and since whitespace is irrelevant, you could change ddi to S \$\endgroup\$ – DJMcMayhem Nov 21 '16 at 19:32
9
\$\begingroup\$

MATL / Golfscript / 05AB1E / CJam: 4 languages, 34 33 bytes

'TURKEY'%"rolls"#];"corn""bread"s
\$\endgroup\$
  • 2
    \$\begingroup\$ Any particular reason for the capitalization of tUrKEY? \$\endgroup\$ – ETHproductions Nov 19 '16 at 18:04
  • \$\begingroup\$ @Ethproductions That's so they're valid statements in CJam and it doesn't error out prematurely in that language \$\endgroup\$ – Luis Mendo Nov 19 '16 at 18:19
  • \$\begingroup\$ Actually it can be all caps. After all, turkey is the most important dish :-) \$\endgroup\$ – Luis Mendo Nov 19 '16 at 18:24
8
\$\begingroup\$

C, sh, Python 3, Nim, Julia, Brainf**k -- 6 languages, 211 209 bytes

#define println(x) main(){puts("turkey");}/*
#[
#=
a=''''
echo gravy
'''
println=lambda x:print("biscuits")
# ]#proc println[T](s:T)=echo"rolls"#--[----->+<]>---.++++++++++++.+++.----.
# =##*/
println("salad")

Languages to menu items:

  • C outputs turkey
  • sh outputs gravy
  • Python 3 outputs biscuits
  • Nim outputs rolls
  • Julia outputs salad
  • Brainf**k outputs corn

Added Julia thanks to @kvill!

\$\endgroup\$
  • 1
    \$\begingroup\$ Julia is possible to squeeze in, for the same bytecount. You can drop the C #include (works in gcc). Rename puts println everywhere except in main(), add julia's multiline comment opener #= above a=''' and change #*/ to # =##*/. \$\endgroup\$ – kvill Nov 20 '16 at 0:01
  • \$\begingroup\$ You can golf this further by removing the exit and joining the single quote to the previous line (a=''''). sh will issue warnings but this is allowed AFAIU. And oh, println[T](s:T)=echo"rolls" works for Nim. Nice answer with all my favorite languages combined! \$\endgroup\$ – kvill Nov 20 '16 at 0:25
7
\$\begingroup\$

ferNANDo / ><> / Gol><> / 05AB1E / 2sable, 5 languages, 178 bytes

!v"`"v"!
     <;ooooo"salad"
"<;oooooooo"dressing
1 0
0 1 1 1 0 1 0 0
0 1 1 1 0 1 0 1
0 1 1 1 0 0 1 0
0 1 1 0 1 0 1 1
0 1 1 0 0 1 0 1
0 1 1 1 1 0 0 1
")\"corn""ab"û"aba"Qi"rolls"
\$\endgroup\$
7
\$\begingroup\$

Befunge-98, ><>, V, Python 2, 05AB1E, Gol><>, Foo, Haystack (the 2015 version), GolfScript, BF, Fission, Minkolang 0.15, Seriously, Axo: 14 languages, 381 bytes

This is a collaborative answer with BlueEyedBeast

I decided to do a 2D approach to this question... Yes, there are 7 2D esolangs!

I have taken inspiration for additional languages to add by BlueEyedBeast's answer (Foo, GolfScript)

<ESC> is the character literal for Escape.

#>!>\'n\'r\'o\'c\,,,,,@'s'a'l'a'dJ,é'g'n+'i+'s+'s+'e+'r+'d+.ó[-]+[----->+++<]>.+++++++++++.+++[->+++<]>++.+[--->+<]>.+++H'turkey'~;oooooooo'sweettea.0-5++++++++fffffffff''`'
#   >99*d1+c3-c89*4+dcc99*2+c!|$l9D3-O93++dOO8+O1+O1-O5+OO1+O95++O.
# >'p'()'u'()'m'()'p'()'k'()'i'()'n'()'p'()'i'()'e'()\
print'biscuits';'pecanpie'#"stuffing"R'c!'o!'r!'n!'b!'r!'e!'a!'d!*<ESC>ddddddSapplepie

Befunge-98

#?!>                                nothing important
  'n                                push 'n'
                                    STACK: [110]
    \                               swap top two stack values (TBH, I'm not really sure what happens in this case)
                                    STACK: [110, 0]
     'r\'o\'c\                      repeat the same for other characters
                                    STACK: [110 114 111 99 0]
              ,,,,,                 output the next 5 top stack values, "corn"
                   @                end program
                                    rest of the code is irrelevant
                                    since program has already stopped

Try it online! outputs corn

><>

Commands are shown in the order they appear

                                    enter from the left, direction = right
#                                   mirror, now the direction will change to left
                                    and it wraps around and comes to the right
                                    and reads code from the right to the left
'`'                                 push this
   ' ... 5-0.aetteews'              push this too
                      oooooooo      outputs the top 5 characters of the stack
                              ;     end program

Try it online! (Copy and Paste only) outputs sweettea

V

             ...<ESC>                 writes stuff over three lines and enters normal mode
                     ddddddS          deletes 3 lines, delete another line and enter insert mode
                            applepie  writes "applepie"

Try it online! outputs applepie (it might take ˜20 seconds for it to run)

Python 2

                                    # first two lines are comments
print"biscuits";                    # prints "biscuits" and ends statement
                'pecanpie'          # dangling (and ignored) string literal 

Try it online! (Copy and Paste only) outputs biscuits

05AB1E

#>!>                                # does nothing important
\'n\                                # push 'n' and delete it
     'r\'o\'c\                      # repeat for other characters
              ,,,,,                 # prints 5 times (since there is nothing in stack,
                                    #                 prints nothing)
                   @                # push the index of the top of stack
                    's'a'l'a'd      # push these characters
                              J,    # join them and print them out
                                    # the rest of the code does not matter
                                    # since there is no implicit print
                                    # because we used the print statement

Try it online! outputs salad

Gol><>

Commands are shown in the order they appear

                                    enter from the left, direction = right
#                                   mirror, now the direction changes to left
                                    and it wraps around and comes to the right
                                    and reads code from the right to the left
 '                                  starting parsing strings
  `                                 escape next character
   '                                gets escaped
    "                               stop string parsing
     fffffffff                      pushes 15, 8 times
           ++++++++                 adds up the numbers, resulting in 135
                 5-                 subtract 4 from it, 130
                   0                pushes 0
                    0               jumps to (130, 0)

#\'n\'r\'o\'c\,,,,,@'r'o'l'l'sJ, ... H'turkey'~;oooooooo"sweettea.0-5++++++++fffffffff""`"
                                              ^
                                       we are here now

                     ˜              removes value at top of stack, '"'
                      "yekrut"      push this string
                              H     Output stack as characters and halt program

Try it online! outputs turkey

Foo

Foo outputs anything in double quotes, that is why I have been careful to not use any double quotes in the other languages. Since "stuffing" is in double quotes, it will be printed.

Try it online! outputs stuffing and then has an error

Haystack (2015)

This uses Haystack's 2015 (not 2016) interpreter since the newer version is invalid. The interpreter for this is haystack.py and not haystack_new.py

Commands are shown in the order they appear

#                                 ignored
 \                                reflection (now it moves downwards)
  >                               set direction to right
   99*d1+c                        Output 'R'
          3-c                     Output 'O'
             89*4+dcc             Outputs 'L', newline, 'L'
                     99*2+c!|     Outputs 'S' and ends the program
                                  Note: '!' is ignored by the interpreter

This program outputs

R
O
L
L
S

and a newline after this output (hey, whitespace doesn't matter!)

GolfScript

                                    first 2 lines are comments
print'biscuits';                    pushes "biscuits" to the stack and discards it
                'pecanpie'          push this
                          #...      comment
                                    implicit output

Try it online! outputs pecanpie

BF

I used https://copy.sh/brainfuck/text.html to convert text into BF. Although there are a lot of , input statements, the BF code runs independent of it.

Try it online! outputs gravy

Fission

For a Fission program to begin, an atom has to be spawned. We see this happening the the third line:

..."stuffing"                                Blah blah blah
             R                               Spawns an atom with direction right
              'c                             Gives the atom the mass of 'c''s ASCII value
                !                            Print the atom's mass
                 'o!'r!'n!'b!'r!'e!'a!'d!    Do the same for other characters
                                         *   Destroy atom, end program

Try it online! outputs cornbread

Minkolang v0.15

#                                Doesn't really do anything
 \                               Reflect, moves downwards
  >                              Changes direction to right
    ... !|                       Does stuff in stack, '!' ignores the '|'
          $l9D3 ... ++O          Uses ASCII character codes to print "applecider"
                       .         Ends program

Try it online! outputs applecider

Seriously

é                          - clear stack
 'g'n+'i+'s+'s+'e+'r+'d+   - load chars onto stack
                        .  - print stack
                         ó - exit

Try it online! outputs dressing

Axo

(Commands are shown the order they are encountered)

#>                                          blah blah
  !                                         rotate direction 90 degrees clockwise

  >                                         go right
   'p'()                                    push char and output
        'u'() ... 'e'()                     repeat for other characters
                       \                    end program

Try it online! outputs pumpkinpie

\$\endgroup\$
  • 1
    \$\begingroup\$ This is pretty awesome :) \$\endgroup\$ – ETHproductions Nov 28 '16 at 16:58
  • \$\begingroup\$ @ETHproductions Thanks! I put a lot of effort into it :) \$\endgroup\$ – Kritixi Lithos Nov 28 '16 at 16:59
  • \$\begingroup\$ Just a little nitpick: the ! In the befunge code takes a 0 from the top of the stack and pushes 1. Therefore, the stack contents when the program starts printing is [110 114 111 99 1]. The character for ASCII value 1 isn't visible (start of heading), so it doesn't visually affect the result. +1 \$\endgroup\$ – MildlyMilquetoast Dec 5 '16 at 21:16
  • \$\begingroup\$ @MistahFiggins I could just change it to $,,,, instead to not output the 1 (without changing the bytecount), but then I would have to change all the permalinks... :) \$\endgroup\$ – Kritixi Lithos Dec 6 '16 at 11:39
6
\$\begingroup\$

Pushy, Python and Brainfuck

This is my first polyglot, so don't go too hard on me... For those whining about byte count, it's 77 bytes, but that's only relevant for the tiebreaker.

"`turkey`"
print('gravy')
#++++++++++[>++++++++++<-]>-.++++++++++++.+++.----.

Pushy prints 'turkey' with a leading newline (as well as a message to STDERR):

"        % Print current stack: just a newline as stack is empty
`turkey` % Push to stack
"        % Print the stack: 'turkey'
p        % Primality check on 'y' (121): pushes 0
r        % Integer root of 0: throws error and exits

Python prints 'gravy', as the first and last lines are treated as comments.

Brainfuck ignores all other characters and except for those on the final line, which create and print the word 'corn'.

\$\endgroup\$
  • 1
    \$\begingroup\$ What's the byte count? \$\endgroup\$ – Kritixi Lithos Nov 20 '16 at 8:46
  • 1
    \$\begingroup\$ Also, can't you use Python 2 to remove the parenthesis and save 2 bytes? \$\endgroup\$ – Kritixi Lithos Nov 20 '16 at 8:50
  • \$\begingroup\$ @KritixiLithos this isn't codegolf.... \$\endgroup\$ – FlipTack Nov 20 '16 at 9:42
  • 4
    \$\begingroup\$ “In case of a tie, the shortest of the tied entries in bytes wins.” It's not entirely codegolf, but you still need the bytecount. \$\endgroup\$ – TuxCrafting Nov 20 '16 at 14:32
  • 2
    \$\begingroup\$ @TùxCräftîñg true, but this has no chance of getting to the tiebreaker anyway \$\endgroup\$ – FlipTack Nov 20 '16 at 15:05
4
\$\begingroup\$

Pip, BF, oOo CODE, ><>, Befunge-93 (Quirkster implementation), Ouroboros, ///: 7 languages, 175 bytes

/'//bisCuItS/`f(>-[--[<]>+>-]<.++++++++++++.+++.----.O@,,,,,,"tuRkey"
"saLaD"1/ooooo;1(
>"YVaRg"^(OoooOoOOoooOoooOOoooOOoOooOooOooOOoOooOooOooOOoOOoOoOOoOOoOOoOOo`OO"sTUfFINg"

Pip

Try it online

A bunch of expressions that get silently discarded (most of which generate warnings, if warnings are enabled), with the expression "sTufFINg" at the end which gets printed.

/ '/ / b      Invert the string "/" and divide it by nil
i s           Two different variables
Cu            Chr(nil)
It            If 10:
S / `...` OO   Invert a Pattern literal and swap it with undefined variable OO
"sTufFINg"    Autoprint this last expression

BF

Try it online

Everything except >-[--[<]>+>-]<.++++++++++++.+++.----.,,,, is comments. This code generates 99 (the character code for c) via the shortest method listed on esolangs.org, then modifies it for o, r, and n. The ,,,, tries to input four characters, but that doesn't affect anything.

oOo CODE

Everything except letters is ignored. Grouping the letters into threes, the codes reads like this:

bis CuI tSf Otu Rke ysa LaD ooo ooY VaR gOo ... OsT UfF INg

and translates to this BF code (try it using Martin's Retina translator):

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

which outputs rolls. (And, interestingly enough, is shorter than the above BF for outputting corn, even with a >< no-op added to make the capitalization line up correctly.)

><>

Run ><> code here

The important part of the code:

/
        /ooooo;
>"YVaRg"^

The IP gets reflected upward, wraps around, and gets sent rightward. "YVaRg" pushes the character codes of gRaVY. ooooo outputs five letters and ; terminates the program.

Befunge-93

The code depends on undefined behavior and probably only works in this implementation.

The important part of the code:

/'                        @,,,,,,"tuRkey"

/ is division. The stack is empty, so the JavaScript implementation I'm using divides 0 by 0 and pushes NaN.

' is an unrecognized character. The implementation I'm using, conveniently, treats unrecognized characters as Reflect commands. (For a less implementation-dependent version, one possible replacement would be 1_.) So the IP goes left again, divides NaN by 0 (getting NaN), and wraps to the other end of the line.

Now "yekRut" (moving RTL) pushes the character codes of tuRkey and ,,,,,, outputs them. Finally, @ terminates the program.

Ouroboros

Try it here

Each line of the code is a "snake" that executes independently.

Snake 1

Since there are no output instructions, the only important part of the code is f(: f pushes 15 and ( swallows that many characters from the end of the snake. The code is now considered to end after .O. Execution continues until the end of the snake and loops back to the beginning. Each time through, the snake gets shorter, until eventually the ( is swallowed. Since the IP just got eaten, the snake halts execution.

Snake 2

"saLaD" pushes its character codes last-to-first; 1/ divides the charcode of r by 1, leaving it unchanged, and ooooo outputs five characters. ; drops an item (no-op because the stack is already empty). 1( swallows the instruction pointer and halts.

Snake 3

"YVaRg" pushes some charcodes; then ( swallows a number of characters equal to the top of the stack, which happens to be 89, the character code of Y. Eating 89 characters is enough to swallow the IP and halt execution.

///

Try it online using my Pip implementation of ///

/'// deletes all single quotes from the rest of the program (which does nothing because there aren't any). Next, bisCuItS outputs as-is. Finally, the rest of the code is an incomplete substitution--there's only two of the three requisite slashes--so it does nothing.

\$\endgroup\$
  • \$\begingroup\$ I like the abuse of the "case doesn't matter" rule to make it work in oOo CODE :-) \$\endgroup\$ – ETHproductions Nov 28 '16 at 16:59
3
\$\begingroup\$

Cubix, Pushy, Brainfuck, V, Python 2 - 5 languages, 89 85 bytes

My second ever polyglot - not very golfed, but it works:

"`turkey`";print'salad'#;"nroc"w!@o;"-[--";;;;{{->+<]>---.---.---..+++++++.␛ddgigravy

(note that represents the literal escape byte, x1B)

  • Cubix prints corn
  • Pushy prints turkey
  • Brainfuck prints ROLLS
  • V prints gravy
  • Python prints salad

Cubix

Test the program online!

Cubix is a language by the challenge author, ETHproductions. The Cubix Interpreter reads the code like this:

        " ` t u
        r k e y
        ` " ; p
        r i n t
' s a l a d ' # ; " n r o c " w
! @ o ; " - [ - - " ; ; ; ; { {
- > + < ] > - - - . - - - . - -
- . . + + + + + + + . d d g i ␛
        g r a v
        y . . .
        . . . .
        . . . .

The code is executed like so:

  • 'salad - does some irrelevant XOR operations on stack, results in 115, 0, 0
  • '#; - push the charcode of #, then pop it again (no-op)
  • "nroc" - push the charcodes for "corn"
  • w - moves the IP to loop on the next line below:
    • !@o; - print and pop last item (terminate if item is 0)
    • "-[--";;;; - push these chars and delete them (no-op)
    • {{ - no-op

Pushy

Test the program online!

Pushy is my own language, and it runs the code like this:

"          \ Print stack. Empty, so prints newline.
`turkey`   \ Push this string
"          \ Print this string
;          \ "End loop": Ignored as there is no loop in progress.
pr         \ Irrelevant stack operations
i          \ "interrupt": exit program.

Brainfuck

Test the program online!

Brainfuck ignores all characters that are not in its list of instructions, resulting in:

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

Which prints ROLLS. Note that this requires an interpreter with wrapping cells, such as the one provided.


V (Vim language)

Test the program online!

V was created by DJMcMayhem, one of our top code-golfers.

V is a program-based version of the text editor Vim. Most characters before the ESC get written into the "file", but ␛ddgigravy deletes all of that and inserts "gravy" instead. The content of the file at the end of the program is printed.


Python 2

Test the program online!

Python is one of my favorite practical languages. Because # is a comment in Python, most of the program is ignored. The code is read like this:

"`turkey`";            # Unused string literal
print'salad'           # Print statement
#...                   # Comment (everything else is ignored)

\$\endgroup\$
  • \$\begingroup\$ Minor nitpick: 'salad'# actually pushes the charcode of s, 0, 0, and the charcode of #, then ; pops and leaves the stack at 115,0,0. \$\endgroup\$ – ETHproductions Jan 21 '17 at 23:19
  • \$\begingroup\$ @ETHproductions yeah, you're right, doesn't affect the program either way really but I'll fix up the description \$\endgroup\$ – FlipTack Jan 21 '17 at 23:20
2
\$\begingroup\$

Python/QBasic/Pip, 3 languages, 41 bytes

More languages possibly TBA.

1#print"corn":end
print("turkey");"salad"

Python

1 is just an expression that gets discarded. # starts a comment. print("turkey") does what it says, and "salad" is another expression that gets discarded.

QBasic

1# is a (double-precision) line number. print"corn" does what it says. end terminates the program. The second line is syntactically valid but never executed.

Pip

Most everything is expressions that get discarded. "corn":e tries to assign to a literal string, which fails silently (unless warnings are enabled). "salad" is the last expression in the program and therefore is printed.

\$\endgroup\$
1
\$\begingroup\$

PHP, JavaScript and BrainF*ck, 178 Bytes

First time I've ever tried a Polyglot - not going to lie, I'm in over my head here...

Golfed:

<!DOCTYPE html><html><body><?php echo "turkey";?></body><script>function A(){alert("stuffing");}//`--[----->+<]>-++.+++++++++++.-----------------.-----------.+++.`
</script></html>

(I didn't dare to write a Thanksgiving food in the HTML code and count that as another language...)

Explanation:

The code needs to be saved into a .php file for the PHP and JavaScript parts.

PHP:

When ran on a PHP server, the PHP part of the code is read:

<?php echo "turkey";?>

This outputs:

enter image description here

JavaScript:

You can call the JavaScript A() function from the browser console:

function A(){alert("stuffing");}

This outputs:

enter image description here

Brainf*cK

The Brainf*ck part is nicely hidden in the comments in the JavaScript section, so it is ignored by the PHP and JavaScript parts:

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

When the whole file pasted into an IDE, this outputs:

enter image description here

I couldn't have done the Brainf*ck part without this text-to-BF website. I originally got it to generate code for "corn" and then in an attempt to learn something about this crazy language, I converted it to "gravy"...or rather "graVY"...

\$\endgroup\$
1
\$\begingroup\$

Python, Clojure, Javascript, Ruby: 4 languages, 113 bytes

1;''''/*
#_(
puts("turkey")
__END__
);'''
1;1//2;'''
1;*/alert("gravy")/*
(print "salad");'''
#_
print "corn";#*/

Thanks to @Sp3000 for most of the code. Surprisingly, I didn't even have to do anything to his original, I just had to prepend the Ruby code.

\$\endgroup\$
1
\$\begingroup\$

///, SQL and JavaScript

/*//turkey/\*/select('corn')
--a;function select(){alert('salad')}

Same construction as with that other holiday-oriented polyglot:

///

/*//turkey/../..   Simply prints 'turkey', does no replaces, stops execution because the second /// block is incomplete

SQL

/*//turkey/\*/    //turkey/\ is seen as a block comment
                  That last \ was added to set apart the following */, completing the block
select('corn')    SQL Select statement, yielding 'corn'
--a;...           Seen by SQL as a comment, ignored

Javascript

/*//turkey/\*/    //turkey/\ is seen as a block comment
select('corn')    Function call to the function 'select', defined below
--a;              Decrement a, effectively a NOP
function select(){alert('salad')}
                  Defines the function select(), giving us 'salad'
\$\endgroup\$
0
\$\begingroup\$

Clojure / Common Lisp / PicoLisp, 39 bytes

(print(if '()'turkey(if""'rolls'corn)))

Lisp family here. '() evaluates to true in Clojure so it proceeds to outputing a symbol turkey. PicoLisp and Common Lisp goes into false branch; "" is true in Common Lisp and thus it prints symbol rolls, empty string is false in PicoLisp and so it goes to printing corn symbol.

Check it online:

https://ideone.com/OD65LB - Clojure

https://ideone.com/M1H5gf – Common Lisp

https://ideone.com/B4x3ns – PicoLisp

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

CJam, Underload, ><>, 39 bytes

'v;"(Turkey)S";"Gravy""
 >'nroC'oooo;";

What CJam sees

  • 'v;: A character literal that is immediately discarded
  • "(Turkey)S";: A string literal that is immediately discarded
  • "Gravy": Pushes the string Gravy to the stack
  • "\n'nroC'oooo;";: A string literal that is immediately discarded.

At the end of execution, the stack is output, which means that "Gravy" is printed.

What Underload sees

  • 'v;": Some invalid commands that are ignored
  • (Turkey)S: Pushes the string "Turkey" and outputs it
  • ";"Gr: Some invalid commands that are ignored
  • a: This causes a segfault on the TIO interpreter since the stack is empty. Execution is terminated.

What ><> sees

  • 'v;"(Turkey)S";"Gravy"" pushes a bunch of characters to the stack (which are ignored). The IP then wraps back around.
  • v sends the IP downwards.
  • >'nroC'oooo pushes the characters in the string "Corn" and outputs them.
  • ; terminates execution. All other characters are ignored.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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