Questions tagged [polyglot]

For challenges involving code that runs in multiple programming languages.

Filter by
Sorted by
Tagged with
278
votes
340answers
117k 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 ...
36
votes
20answers
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 ...
24
votes
27answers
4k 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
64answers
6k 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
5answers
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
7answers
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 ...
75
votes
16answers
13k 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. ...
59
votes
55answers
10k 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 ...
17
votes
2answers
605 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 ...
38
votes
17answers
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
6answers
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'...
193
votes
119answers
25k 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 ...
28
votes
43answers
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): ...
21
votes
12answers
1k 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 ...
70
votes
16answers
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 ...
11
votes
1answer
384 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
3answers
335 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 ...
18
votes
10answers
2k 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 ...
26
votes
10answers
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 ...
53
votes
33answers
8k 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 ...
44
votes
33answers
15k 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: ...
18
votes
8answers
1k 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 ...
100
votes
40answers
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, ...
26
votes
6answers
1k 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 ...
14
votes
7answers
509 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 ...
12
votes
1answer
381 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 ...
17
votes
15answers
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 ...
28
votes
10answers
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 ...
25
votes
1answer
1k 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
15answers
731 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
19answers
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 ...
10
votes
6answers
1k views

Polyglot self-interpreter time

Your task is to make a program which interprets the language it is run in, but also works in many languages. Let's say you make a Brainfuck-Underload self-interpreglot, as it will be called. Run in ...
43
votes
14answers
9k 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. ...
39
votes
17answers
3k 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 ...
4
votes
8answers
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 ...
4
votes
3answers
452 views

Polycops and Robbers (Robbers' Thread)

This is the robbers' thread, the cops' thread is here A polyglot is a program, that without modification, can run in multiple languages. Robbers' Challenge First, find a vulnerable cop's answer, ...
13
votes
10answers
918 views

Multi-lingual Challenge

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 ...
15
votes
9answers
2k 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 ...
1
vote
1answer
215 views

Polyglot "Hello world" in Fortran and Lisp [duplicate]

Simple challenge: The code must be both valid Lisp and valid Fortran, and must print out "hello world" in both. Note: I've sunk about 5 hours into this at this point, I'm not even sure it's possible ...
93
votes
19answers
17k 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 ...
163
votes
127answers
32k 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 ...
63
votes
43answers
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 ...
0
votes
1answer
225 views

Polyglot Iterative Quine

Introduction A polyglot is a program that is valid in multiple languages at once. An iterative quine is a program that outputs another program that outputs another program that outputs the source of ...
20
votes
5answers
2k 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 ...
-9
votes
1answer
598 views

Don't get banned from stack exchange! [closed]

I'm sure this is going to spark some controversy, but let's do a practical demonstration. The objective of this is simple, using the new code of conduct and no input, print out my pronouns ( "he/him"...
9
votes
6answers
784 views

Backwards and forwards polyglot quine!

You must make a polyglot that outputs its source code in one language and its source code backward in another. Unlike the normal rules, you are allowed to read the current file or use a builtin to get ...
-2
votes
2answers
285 views

Write a "hello world" program that can be compiled/interpreted as two different languages simultaneously [duplicate]

Rules: Your program must print "hello world" when executed Your program must be interpretable or compilable into 2 or more languages Your program must require no input or arguments Languages with ...
12
votes
21answers
1k views

An OEIS polyglot

This is an answer-chaining challenge relating to the OEIS. Oh, the justification for this is because a company needs one program to print out their OEIS sequences real bad and they have every ...
59
votes
18answers
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 ...
106
votes
15answers
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 ...