Questions tagged [polyglot]
For challenges involving code that runs in multiple programming languages.
107
questions
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 ...
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 ...
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 ...
107
votes
14
answers
20k
views
Possibly quit your job with a polyglot
Despite your protest, you have been put to work by your boss on a program that takes a single unsigned integer as input and prints the string "prime" if that integer is prime and "not ...
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, ...
96
votes
19
answers
19k
views
When was this language released?
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that ...
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.
...
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 ...
70
votes
10
answers
6k
views
Rock, Polyglot, Scissors
Write a program that is a polyglot in three languages that plays rock–paper–scissors.
The input for any version of the program is always one of the strings rock or ...
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 ...
64
votes
43
answers
9k
views
π Day puzzle for 3/14
Happy π Day. The goal of this question is to calculate the area for a circle of radius 3, where A = πr².
The catch is that you have to use the constant π that is defined in a different language than ...
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 ...
59
votes
18
answers
7k
views
Count like Chuck Norris
As is well known,
Chuck Norris counted to infinity. Twice
Besides,
Chuck Norris can count to infinity backwards.
Also, although perhaps less known, Chuck Norris can speak a little Spanish in ...
51
votes
16
answers
4k
views
Tips for creating polyglots
A polyglot is a program that can be run in 2 or more different programming languages.
What general tips do you have for making polyglots, or choosing languages that are easy to write polyglots for a ...
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:
...
45
votes
3
answers
2k
views
Klein Topololyglots
Klein is a 2D language I have designed that can be embedded on 12 different topological surfaces. A Klein program can be run on different surfaces by changing the command line arguments.
The ...
44
votes
32
answers
3k
views
Polyglot Anagrams Cops' Thread
This challenge has two threads. This is the cops' thread. The robbers' thread is located here.
Your challenge is to choose an OEIS sequence and write two full programs in two different languages that ...
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.
...
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'...
41
votes
12
answers
3k
views
Polyglot the OEIS! [duplicate]
Note: This challenge has been moved to Polyglot the (non constant) OEIS! to avoid closure.
Introduction
We all know and love the on-line encyclopedia of integer sequences (OEIS). So what if we made ...
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 ...
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 ...
39
votes
15
answers
3k
views
What will you bring for Thanksgiving?
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 ...
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 ...
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 ...
31
votes
7
answers
2k
views
Three polyglots, two period-two quines, and one code-golf challenge
Produce a program A such that running it in language A produces Program B, and running program A in language B produces program C.
Program B, when run in language B produces Program A, and running ...
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 ...
30
votes
2
answers
5k
views
What code compiles in the most number of languages? [closed]
Excluding trivial programs, what code compiles in the most number of languages?
(By "trivial" I mean to exclude answers such as the empty program or text that will be echoed directly.)
The following ...
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):
...
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 ...
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 ...
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
...
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
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 ...
26
votes
2
answers
3k
views
Write a Palindrome-Polyglot-Quine
Write a "palipolyquine": a program that is a quine, a polyglot, and a palindrome.
Rules:
The number of polyglot languages is more preferable than code size.
The shortest answer (in bytes) wins, in ...
25
votes
6
answers
1k
views
Polyglot the (non constant) OEIS!
Disclaimer: This is heavily inspired by "Polyglot the OEIS!" but fixes the problem that lead to closure (see the output section) and was re-posted as to not invalidate answers.
Introduction
...
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 ...
24
votes
7
answers
1k
views
Fake divisor sum polyglots
The task
In this challenge, your task is to write a program in a programming language L that takes a positive integer n, and outputs the sum of the proper divisors of n (sequence A001065 on OEIS).
It ...
23
votes
24
answers
2k
views
Polyglot Anagrams Robbers' Thread
This is the robbers' thread of this challenge
The cops will choose an OEIS sequence and write two full programs in two different languages that produces that nth item in the sequence when given an n ...
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 ...
22
votes
7
answers
789
views
Print Polyglot Pieces
Typically, polyglots are constructed in such a manner that each language can ignore parts of the code that are present for other languages, by wrapping them in string literals, using comment syntax, ...
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 ...
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 ...
21
votes
4
answers
536
views
Multiple program Quinecatenate!
Your task is to give three different languages A, B, C, and write two different programs P and Q such that:
P is a quine in language A, but not a quine in B nor C;
Q is a quine in language B, but ...
20
votes
5
answers
3k
views
Print your char count in words, in many languages
This challenge is inspired by my earlier challenge "Create a program that prints the amount of characters it has, in words".
This challenge's rules are simple: make a program that prints its ...
20
votes
6
answers
1k
views
Anaglot Polygrams
Task
Write some code that can be rearranged into n different programs in n different languages each outputting a distinct number from 1 to n.
No two languages should be the same however different ...
20
votes
1
answer
808
views
Golf you a Double Quine for greater good!
Good Evening Ladies and Gentleman.
Tonight - we have a code challenge. A competition that will be defined not in the amount of points (a la Asteroids) but simply whether you can finish it (a la ...
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 ...
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-...