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, 2 in language number two, 3 in language number three etc.


  • The output must be only the integer, but trailing newlines are OK.
  • The code can't take input of any kind
  • Different major versions of the same language are considered unique. So, your code can be executable in Python 2 and Python 3, however Python 2.5 and Python 2.7 are not considered unique.
  • You may use a new language if and only if it has an esolang/wiki article, available interpreter and documentation, and has been used by at least two users on PPCG prior to using it in this challenge. It must also adhere to these 4 rules.

The score of your submission is the number of bytes in your code divided by the number of languages it can run in cubed. So, a 54 byte solution that is executable in 3 languages will have a score of 2:

54 / 3^3 = 2  

Lower score is better.

  • 6
    \$\begingroup\$ @muddyfish You might be able to fetch the minor version within the code, which would then give you free solutions for all 2.7.1 to 2.7.n. (Actually, sweerpotato does just that with major versions.) \$\endgroup\$ Dec 3 '15 at 17:04
  • 15
    \$\begingroup\$ I think maybe shortest solution by language doesn't make sense here... :P \$\endgroup\$ Dec 3 '15 at 20:44
  • 4
    \$\begingroup\$ @Mego Neither am I, that's why I leave sarcastic comments about the problem so that other people find out about it :P \$\endgroup\$ Dec 4 '15 at 3:50
  • 13
    \$\begingroup\$ I just wanted to congratulate you on how well-balanced your scoring is. When code challenges mix two quantities into one score the balance is almost always off such that the best answer will just optimise one of the scores without having to consider the other one at all. The cubic weight of the number of languages was perfect here... while it was always possible to add another language it was always a very nice (but doable) challenge to do so in the number of bytes available. :) \$\endgroup\$ Dec 5 '15 at 23:49
  • 25
    \$\begingroup\$ In this PPCG challenge we've been collaboratively building a polyglot. It now has a better score on this challenge than the leading entries submitted to this challenge, but it wouldn't make sense to copy a group effort that's constantly being improved over, so I'm just dropping a mention in the comments here. \$\endgroup\$
    – user62131
    Mar 17 '17 at 23:56

40 Answers 40


Alphapolyglot, 8 languages, 37 bytes, score 0.072265625

"6";;7iiiio hkaeeeaeaeawxzz ax zaCM

Features AlphaBeta, Beatnik, Commentator, Deadfish~, evil, Foo, Golfscript, and Husk. Thanks to Leo for helping with Husk.



8"6";;7iiiio hkaeeeaeaeawxzz a       # Garbage
                              x z    # Clear register 1 and 3
                                 a   # Add 1 to register 1
                                  C  # Set register 3 to register 1
                                   M # Output register 3 as a number


iiiio hkaeeeaeaeawxzz ax zaCM is 5 50 9 17.

5 50 pushes 50 (2 in ASCII) 9 outputs the top of the stack as a character. 17 exits the program.


There are 3 spaces in the program, each one increments the active accumulator.


8"6";;7iiii                          # Increment 4 times
           o                         # Output as a number
             h                       # End program 
              kaeeeaeaeawxzz ax zaCM # Garbage


8"6";;7iiiio hk                      # Garbage
               aeeeaeaea             # Increment and weave the accumulator to 53 (5 in ASCII)
                        w            # Output accumulator as a character
                         xzz ax zaCM # More garbage


8                                    # Garbage
 "6"                                 # Output 6
    ;;7iiiio hkaeeeaeaeawxzz ax zaCM # Garbage


8                                    # Push 8
 "6"                                 # Push the string 6
    ;;                               # Pop and discard twice
      7                              # Push 7
       iiiio hkaeeeaeaeawxzz ax zaCM # Garbage


The first line is executed first.

8 # Return 8

The second line isn't executed.


JavaScript, HTML and PHP, 72 bytes / 3^3 = 2.67


In HTML, this will print the leading 1, ignore the <!window?2:2//> tag, and the rest is an HTML comment.

In JavaScript, it evaluates 1<!window?2:2 and outputs 2 (this must be run in a console) and the rest is a comment.

In PHP, the following is output from the server: 1<!top?2:2//><!----><script>document.body.innerHTML=3</script> which replaces HTML's 1 with 3.

  • 1
    \$\begingroup\$ Welcome to PPCG.SE! Great first post! Two things: we don't usually like REPL-based answers (the Javascript program). Additionally, the PHP code does not seem to run when I put it into an online interpreter, how exactly does the PHP work? \$\endgroup\$
    – GamrCorps
    Dec 4 '15 at 22:56
  • \$\begingroup\$ Thanks! Well, it's technically PHP + HTML (ie. if this is the source code for code.php, visiting site/code.php in a browser displays 3. \$\endgroup\$ Dec 5 '15 at 0:21
  • \$\begingroup\$ Try it here: mowbl.com/se.php. \$\endgroup\$ Dec 5 '15 at 0:23

Python 1,2,3, Pyth, Seriously 40 bytes/5^3 = 0.32

import sys

Python 1,2,3 prints their version

This is based on the same code by sweerpotato. The # starts a comment so the first line is not compiled.

Pyth prints 4

#4X.q starts a while loop, X does something unnecessary, and .q quits the program.

Seriously prints 5

#4X.q5 starts out with # which does nothing, then 4 is pushed to the stack, X clears the stack, .q does nothing, and 5 is pushed on the stack and an invisible character (hex code 7f) quits the program and prints what is on the stack.

  • \$\begingroup\$ that's a boring solution. \$\endgroup\$ Apr 2 '20 at 15:11

16 languages, 149 bytes, score 0.03637695312

1` FSR3U3%3&(()())#💬5💬➡MoOMoOMoOMoOMoOMoOOOM++++++++.$:H@@@@@@@.   {-   !*/}(10)aeeeaeeawaaaaaw> 11
print 13
[ [

WIP, I plan to add a lot more.

  1. Element
  2. Brain-Flak
  3. SimpleStack
  4. Cubically
  5. Emoji
  6. COW
  7. Agony (outputs via raw ASCII)
  8. Beam
  9. Commentator (currently broken but according to the language spec should work fine)
  10. Straw
  11. RProgN
  12. Emotinomicon
  13. S.I.L.O.S
  14. Charcoal
  15. Fission
  16. evil

Brainglot, score 20/4^3 = 0.3125


1. brainbool

Brainbool only sees [>+<]>+.. The loop never runs, and the > just moves the pointer, so it's basically just +.. The + flips the bit, and the . outputs the current bit, which is 1.

2. brainfuck

Brainfuck only sees -[>+<-----]>--+.. The -+ can be removed, which results in -[>+<-----]>-.. The part before the . is just the wrapping program for 50 on the esolangs wiki.

3. Extended Brainfuck Type I

Extended Brainfuck Type I only sees -[>+<-----]>-$-!+. The $-! can be removed, leaving -[>+<-----]>-+., where the -+ can be removed which turns it into -[>+<-----]>.. The part before the . is just the wrapping program for 51 on the esolangs wiki.

4. Brainlove

Brainlove sees the full program. The (-) and $-! can be removed, leaving -[>+<-----]>+.. The part before the . is just the wrapping program for 52 on the esolangs wiki.


C C++ Python Ruby, 163 bytes

Score = 163/4^3 = 2.55

#include <stdio.h>
#if 0
C = 3
""" "
C = 4;\
" """
#ifdef __cplusplus
#define A 49
#define A 50
#define print(X) main(){putchar(A);}

C, Python 2, Python 3, 99 bytes / 3 languages ^ 3 = 3.666677 points

Python 2 and 3 both use a version string, and the first character is the major version number. C prints 1, Python 2 prints 2, and Python 3 prints 3.

#include <stdio.h>/*
import sys
#define pass main(){printf("%d",1);}

6 languages, 31 bytes, 31/6^3 = 0.1435

As soon as I add another language to it the score gets worse, here is what gave me the best result so far:

kill -l|wc|dc -e\?58%8/1+p#^[cc6

1-5: Various shells + dc

The shells see this, the rest of the line is a comment:

kill -l|wc|dc -e\?58%8/1+p

The shell's output for kill -L is different, their output gets piped to wc to count the number of bytes (N) and compute (N % 58)/8 + 1 which coincidentally gives the right result.

  1. Dash: Try it online!
  2. ksh: Try it online!
  3. tcsh: Try it online!
  4. Bash: Try it online!
  5. Zsh: Try it online!

6: Vim

The key k doesn't do anything with the buffer, i switches to insert mode and the following characters get typed. After # there's an ^[ character so Vim switches back to normal mode. cc deletes the line and switches to insert mode where we insert 6.

Here's how it looks in Vim:

inside vim

Try it online!


∞-ish, 12 7 bytes


Non-competing as language postdates challenge and this is rather cheap. This prints:

 B3       set top face sum to Cubically version
   +0     add top face sum to notepad
     -8   subtract !issolved(cube) from notepad
       %  print notepad

Basically, B3 gets the cube state to this in 3x3x3:


As you can see, the top face sum is 3. As the smallest possible cube is a 2x2x2, we have to subtract 1. In Cubically 4x4x4, the cube would look like this:


Javascript (spidermonkey), PHP CLI, Perl

41 bytes, 41/(3**3) = 1.52


If you try to execute it using normal Javascript rather than spidermonkey, it will do ctrl+p.


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.