Questions tagged [polyglot]
For challenges involving code that runs in multiple programming languages.
107
questions
66
votes
60
answers
11k
views
Determine your language's version
Your challenge is to write a polyglot that works in different versions of your language. When run, it will always output the language version.
Rules
Your program should work in at least two versions ...
26
votes
14
answers
3k
views
Reverse the polyglot, change the language
Task
Write a polyglot in two languages that when run, outputs the name of the language it is run in. Additionally, this program must also output the other language's name if the source code is ...
26
votes
11
answers
2k
views
404 - Unique 404 page not found
Inspired by a polyglot on the Stack Overflow 404 page:
Goal
Your goal is simple, to create a polyglot that outputs the number 404, and then terminate, in as many languages as possible.
Restrictions
...
301
votes
451
answers
125k
views
Add a language to a polyglot
This is an answer-chaining challenge in which each answer builds on the previous answer. I recommend sorting the thread by "oldest" in order to be sure about the order in which the posts are ...
-2
votes
1
answer
84
views
PHP+C polyglot solution to mixed types
Some built-in functions in PHP return mixed types, like file_get_contents that returns both string or ...
103
votes
41
answers
13k
views
The Versatile Integer Printer
Write a piece of code that is executable in at least three different languages. The code must output the integer 1 in language number one, ...
18
votes
12
answers
3k
views
Make a polyglot generator
A polyglot is a program that runs in several languages.
Your challenge is to:
Choose at least two languages (Different versions count as different languages)
Create a program or function that takes ...
41
votes
18
answers
4k
views
Overlapping Polyglots
Unlike many C&R challenges, this does not require a separate robbers post; the goal of the robbers is to crack the previous answer and then post a new one as a cop.
As answerers, you will write a ...
14
votes
13
answers
2k
views
Write a Program in Disguise [closed]
The challenge is to create a program that solves any one of the HQ9+ problems while looking like another language.
Note: This is not a golf challenge.
Rules:
The program must perform one of the ...
61
votes
40
answers
9k
views
Calculate a square and a square root!
You must make a polyglot that outputs the square of the input in one language and the square root of the input in another. The shortest answer in bytes wins!
You must have a precision of at least 3 ...
16
votes
2
answers
748
views
Pristine Polyglots
As the title says, you are to create a pristine program in as many languages as possible. A pristine program, taken from here, is:
Let's define a pristine program as a program that does not have any ...
18
votes
16
answers
3k
views
Plus or minus polyglots!
Your submission must take a list of numbers (in whatever list format your language supports, or using multiple function / command-line parameters) or a string of numbers separated by any character ...
7
votes
1
answer
537
views
Comment-free polyglot with different, nontrivial, behaviour per language
This challenge is inspired by this other challenge, which you may want to read first for some context. However, a competitive answer is likely to look very different, so after reading some posts on ...
18
votes
3
answers
811
views
Universal Unicode Clock
Plot contrivance
You wake up to find that something has gone horribly wrong! Your time machine has malfunctioned and you are lost sometime between June 2022 and October 1991.
You check the computer ...
21
votes
15
answers
2k
views
Polyglot Quiz (Cops' thread)
This is the cops' thread of a cops-and-robbers challenge. The robbers' thread can be found here
In this challenge as a cop you will choose two programming languages A and B, as well as a non-empty ...
9
votes
9
answers
2k
views
Polyglot Quiz (Robbers' thread)
This is the robbers' thread. For the main rules to this challenge see the cops' thread
In this challenge, robbers will choose a cop's vulnerable or safe post and try to figure out a pair of languages ...
5
votes
9
answers
1k
views
Polycops and Robbers (Cops' Thread)
This is the cops' thread, the robbers' thread is here
A polyglot is a program, that without modification, can run in multiple languages.
Allowed languages
Any language that was made before the ...
14
votes
9
answers
3k
views
Build a polyglot for Hello World
Produce a text file that prints "Hello World!" in as many programming languages as possible when compiled/interpreted, while also being as short as possible.
The score for your submission is ...
197
votes
120
answers
27k
views
I'm not the language you're looking for!
Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this.
Challenge
You will have to write a program that ...
6
votes
1
answer
213
views
Need some feedback with PHP+C polyglot code and class/struct properties [closed]
If you consider the following PHP+C polyglot snippet, there is a problem regarding class property access in the printf call:
...
43
votes
14
answers
10k
views
99 Bottles of beer, 99 languages [closed]
The goal is to write a simple "99 Bottles of Beer" program .. that is valid in at least 2 distinct languages (e.g. not Python 2 and Python 3). It must be a complete file that will run or compile.
...
19
votes
15
answers
2k
views
Two In One: Guess That Language - Cops
Robber's challenge
This cops-and-robbers challenge challenges the Cop to write a non-empty program that, when run, produces some non-empty output in language A, and, when reversed, produces some non-...
9
votes
10
answers
628
views
Two In One: Guess That Language - Robbers
Cops' challenge
This cops-and-robbers challenge challenges the Cop to write a non-empty program that, when run, produces some non-empty output in language A, and, when reversed, produces some non-...
165
votes
128
answers
33k
views
Trick or Treat polyglot
Since Halloween is coming up I thought I might start a fun little code golf challenge!
The challenge is quite simple. You have to write a program that outputs either ...
6
votes
2
answers
290
views
Case Conversion Polyglot
Your task is to write a program that performs case conversion from plain text, and other case formats, into one of the specified formats below. Inputs will be either plain lowercase text, or one of ...
29
votes
21
answers
4k
views
Add a hidden language to a polyglot
Inspired/mostly copied but I don't think it's a dupe. Also Inspired.
In this challenge, you will create polyglots that include all languages from previous answers, and another language which you won't ...
46
votes
34
answers
16k
views
Wait, what language is this?
Recently I had the pleasure of writing a Haskell program that could detect if the NegativeLiterals extension was engaged. I came up with the following:
...
-13
votes
5
answers
343
views
12 with no 1234567890, but polyglot
This is my 12th question, so I thought of this idea.
Goal:
Output 12, with any preceding or trailing whitespace permitted
In as many languages as possible (where different versions or flags count as ...
71
votes
17
answers
6k
views
Write a polyglot that prints the language's name
Your task is to write a program that executes in as many languages as possible, with as few characters as you can. To avoid trivial solutions, the program must print the name of the language it was ...
6
votes
1
answer
665
views
Irradiated Polyglots
Design a function or program that, when run normally, outputs the triangular numbers. However, when any single character is deleted, the program/function should not function in the original ...
29
votes
44
answers
6k
views
This code errors on *this* and *that*, is it really written in them?
Inspired by I'm not the language you're looking for!
Challenge
Choose two different programming languages, and write a program that prints the following line to stdout (or equivalent):
...
36
votes
21
answers
4k
views
Write a Polyquine
A polyquine is both quine and polyglot.1 You are to write a quine which is valid in at least two different languages. This is code golf, so the shortest answer (in bytes) wins.
1 I made that up. Or ...
16
votes
7
answers
582
views
Inspired by HQ9+: 4-Behavior Polyglot
Create a program that can be run in 4 different languages such that:
One language prints "Hello World!"
One language outputs its own source code
One language outputs 99 bottles of beer on ...
24
votes
27
answers
5k
views
Valid Through The Ages
Inspired by this question on SO, your task is to produce a program that is valid in (at least) two major versions of your chosen language that produce different output.
Rules
Any language that has ...
35
votes
64
answers
7k
views
'abc' and 'cba'
Your task is simple, write a single code snippet that when executed in one language outputs only the string 'abc' and when executed in another language outputs ...
17
votes
5
answers
1k
views
Are you a probabilist or a physicist?
Hermite polynomials refer to two sequences of polynomials:
The "probabilist's Hermite polynomials", given by
$${He}_n(x) = (-1)^n e ^ \frac {x^2} 2 \frac {d^n} {dx^n} e ^ {-\frac {x^2} 2}$$
...
31
votes
7
answers
2k
views
Write a C / C++ Polyglot [closed]
This challenge's concept is pretty simple. All you have to do is write a program that will compile as both valid C and valid C++! Well, there are some catches. The program must behave differently when ...
76
votes
16
answers
14k
views
Hello World in Multiple Languages
Task
Create a program or a function that is valid in multiple programming languages, and when compiled/interpreted as a different language outputs "Hello, World!" in a different natural language.
...
17
votes
2
answers
645
views
Quine/Error Quine Polyglot
Your task is simple: Write a program that can be run in two languages. It should be a normal quine (prints its own source code) in language 1, and should be an error quine (generates an error message ...
40
votes
17
answers
4k
views
Golf a mutual quine
Using two languages of your choice, write the smallest “mutual quine” you can.
That is, write a program P in language A that outputs the source code for a program Q in language B, such ...
42
votes
6
answers
1k
views
Overcoming cluster size
Fed up with the reliability of flash storage, you decided to store all your programs on one of those good old 1,440 KiB floppies. However, after copying not even 3,000 programs, the disk was full. How'...
22
votes
12
answers
2k
views
Restricted Polyglot
Polyglots are programs that are valid in multiple programming languages simultaneously. Most such polyglots are written in such a way that certain constructs of one language are interpreted as ...
11
votes
1
answer
411
views
Cyclic Polyglot Challenge (Cops)
Cyclic Polyglot Challenge
This is the cops thread. You can find the robbers thread here.
Cyclic Polyglot
A N-element cyclic polyglot is a complete program that can be run in N different languages. ...
8
votes
3
answers
749
views
Polyglot Interpreters
Challenge
Choose any number of languages. Call this set L.
Write a program so that running it in any language in L produces an interpreter for a different language ...
19
votes
8
answers
2k
views
(Error) quines, hello world, polyglots, oh my!
Introduction
A quine is a program that outputs its own source code. For example, a well-known Python quine is _='_=%r;print(end=_%%_)';print(end=_%_). Running it ...
26
votes
6
answers
2k
views
Build an alphabetised polyglot
As TIO can show, every letter of the Latin alphabet is represented when it comes to languages. For every letter there is at least 1 programming language whose name begins with that letter. Your task ...
28
votes
10
answers
2k
views
GCD / LCM Polyglots!
Your challenge is to make a program or function that outputs the GCD of its inputs in one language and the LCM of its inputs in another. Builtins for GCD or LCM (I'm looking at you, Mathematica) are ...
28
votes
1
answer
2k
views
Program that compiles into itself
We've had lots of questions about quines, programs where the source code and output are identical. For compiled languages, there are other combinations: we've already had a question about writing a ...
15
votes
15
answers
1k
views
Restricted-source polyglot string
Your goal is to write a program that prints the string abc in two languages. However, while the full code will print abc in one ...
21
votes
19
answers
5k
views
The Return of FizzBuzz
Intro
Beauty lies in the eye of the beholder. Output lies in the choice of the compiler. There are some codes that give different outputs based on what language they are executed in. Take for ...