After yesterday’s piece on the 128 language Quine Relay, I had to follow up with this polyglot program on Stack Overflow’s Code Golf forum, which at the time of writing, works in 191 languages and is still actively updated.

The nth program to be submitted must run in n different languages; specifically, all the languages added in previous programs to be submitted, plus one more. The program must output 1 when run in the first language used in answers to this question, 2 when run in the second language, and so on.

A polyglot program is closely related to a quine relay; where a quine relay is run in one language to produce a program in another, a ployglot program is a single program which can be interpreted as-is in more than one language – often to produce different results.

It begins with a Python 3 program, that prints 1:

print(1)

To which a program in V (vim) was added, which prints 2, respecting the Python 3′s program:

print(1)#i2

This works because everything up to the # is ignored by V, and the i following the # is read as insert, inserting the value 2, while # marks a comment in Python 3.

From there, a string of 2D languages are added, which adds alternate program flows to the program, useful in that it’s easier to avoid problematic characters intended for other languages, but adding another complication to keep track of as the program evolves.

Many entries take advantage of symbols that denote comments in one language and not another, like with the Python example above. Others use differences in whether a value is treated as true or false:

In Python 2, ½ is 0, which is a falsy value, which makes Python print 5. In Python 3, ½ is 0.5, which is a truthy value, which makes Python print 1

The great feature of this thread is the detail given by many of the participants in their explanations of how and why their entry works. It is a great intro in how to write a polyglot. Also, it’s still an open contest, meaning there’s time to take part in expanding this monstrosity of code. It officially closes when there are 14 days of inactivity, at which point the second-to-last entry wins (to make sure people don’t intentionally post changes that make their entry imposible to follow).

UPDATE (3/11/2020): I am amazed to report that nearly two years later, this polyglot is still growing. The already-enormous program has introduced more than 90 additional languages since the initial posting here, mostly esolangs. Wenyan lang (whose creator will be interviewed in an upcoming post) has been added, a fairly straightforward addition, since it recognizes only Chinese characters. PILOT, a 1960s precursor to LOGO, is represented. Fungoids include Ahead, Befunge-97 and Befunge-96, which has a particularly informative message, explaining the changes necessary to not break the Ahead and Befunge-97 implementations. Befunge-93 and Funge-98 were added much earlier.

As of the time of writing update, it’s at 191 languages 282 languages (over 9k 13k of text!), the latest adding PHP Canvas, and it looks like this (good luck making sense of it):

#16 "($?63lv+'50;+'51;5 5 %$\--2$[# #@$]aat_"  /*{\D8gv ef26q[if.q8=P,k]PPX~_~^xy)\('#CO|"14"  7 9 7 9                                         7 222222222222222222222222                                      ##*/
#/*1&7//```"`     [>.>        .]~~)['][7aat_                        '(22)Siii/ \psddpsd;oh #####]#######++(- #### ##-[######??mxf####xAegguEay######i#u####Ft#######MZWWW####WWWWWW zR###### # ####  #######:_a5# 202ø!},{P_<Ám/e!<ÁmOe!<É}M<ÁmS15%!!%BB44,222%!!%BBPZPYAAA4D,5P[5?4-0!<½!!22<2/!]ss1]'[kX"204".â'_PPQss 7 999993 1 7 3 1 8 1 1 55 k zzzzkf kf k zzzzzd kf k zzzzza kf bfz #z#111#y#y#y#_# coding=utf8               ! 1>?7ДOq#t#>2/Wr#t#t#q#68#r#t#t#68#q#63#r#t#t#6v#>#</Wr#6}#y/===Wr#7ЯOq#>J7Д/Wr#y<Wr#>5/Wr#t#t#6y#>-=/Wr#6|#>6/Wr122! 1退              @[[[["472"?]]]]******<  
#>x   >>IF 2>2*>      18&1&           nthte \#184O@  nthieo  nthneo     anet/112\    ##### #######   # #    ##### h#115#  o#    ##### ####  ###   #### # W#W#####WW#WWWW#####W####WW###WWW####W#WW#W#####WW#WWWW#W\aa*7+42@n;WWWWWWWW;WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWR
# 36!@`D//<> ++++++::@\_       / 78"oo@"    xx   ; L         >"082",,,@_   x-----x########    ## ### ###### ######## #### ##### ####### ##### ###    # # #### ### ##### ####### ##### ###    # # #### ### ##### #EEEEEδΘΔΔΔΘΔΘλ
#comment -[v]>>>>>>>>> >>">r"{\>>>>>> xxxxxxxxxxxxxx [>]R 10G|'53'S 101111xxxxxxxx # ##########>>###>##>#####>>##>####>##>#>#####>>##>#####>####>>>#####>##>#>##>>##>####>>##>#####>####>>>##### ## # ##  ## ####
#~// x    v>>>>>>>>@!:!8:6:2/_ xxxxxxxxxxxxx [@,,,"279"]>252O>"01",,@_ 9xxxxxxxxxx #????!?!??!??!!!!???!?!??!!?!?!!!!!?!!!!?????!????????????????????! >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>                
#[#[]]x   >>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>R.-;---.>>>>>_xxxxxxxxxxx #v
#- ! ++R+++  +++++++++\++++++++++++++++++++++++++++++++++U+.._+++++++._++o+++o--ox #
####################################################################################>
 #{{{{]~*[~*_+++++++[>+++++++<-]>+._+++++._+._@]+-}}[.^+;;+;;+;;+<>;;+;;+;;+;;;;;;+;; +;;.._]}--<^>++[+++++[>+++++++'4o'6o@<-]>._++++._+++._^<]+-+<[<=oC<=oC<._>>>>-]^>[<+++++[>++++++++++<-]>@@+.---@._+>$] )++$--![+++[>+++++++<-]>+._+++++.._>](  <<>> }<}>}[<}}<<}<<<<<}<<}<<<<}<<<}}}<}}<}}<}}<}}<}}<}}}<}}<<<<<<<<<<<}}}<}}<}}<}}<}}<}}<}}}<<<<<<<<<<}]  >>\[/>\/\>>>>>>>]>\[./>>\/\./\/>>>\./]  [[[
#{  
# []-main=-[165]- ### M MMMMMMMnnMnnnMnMMMMMMMnMMnnnnnMMnMnMnnMnMnnnnnnMnMnMMMMMMMMnnMnMnnnMnMMMM
#*  //:1*23/5x%6E2
#cs  
#2""/*  
#|9999 9 9
#9 999 99 9999 9
#`⟪`⟪\⟫9
#<<<# 9 9999 bqbqbqLzLzLzqtqtqtTcTcTcRqRqRq TzTzTzRtRtRtMbMbMbPsPsPsTqTqTqAbAbAbTmTmTmBqBqBqMtMtMtUgUgUg
#=  ($?$?0l0v01k1k0l0i 0r 0h0h1d111 0e 0y0y 0mo1d0y0e0e001d0i0f 0g 0n0n110mo0n0t 0t0mo0f0t0g0g0f0h0r0r0i0001k10v 0v0l11110000011100|_ )\
[ '`e```.1.0.6i_]56pq['];#/\\/;print 24; exit}} __END__/
###\MoOMoOMoOMoOMOOmoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOMoOmOoMOomoomoOOOM\// >+@+-@@@@=>+<@@@=>+<?#>;?\:-._++._++++._#/<?\>3-++._6+---2._#/++++++++++++++++++++++++++++++++++++++++++++++++._++._++++++.>!\
'wWWWw;WW;WW;wv;w;;WW;wW;WW;wv;wW;WW;w_;WW;WW;WW;WW;wW;WW;Ww;W;WW;WWWWwW;;;W\W/WWWWWwwwwvwWWWwWWWWwvwWWwW\WWwvwWWwWWWwvwW/Ww\WWW ho ho ho ho // ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho ho hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi MU ([])  ({}<(((((()()())){}{})){}{})>)(({})){}{(<(<()>)({})({}<{}>({}){})>){({}[()])}}({}){}({}()<()()()>)  (<><()>){({}[()])}{  #(((()()()()())()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()())(()()()))  ((((((((\';  a=$(printf \\x00);b=$(echo -n $a|wc -c);case $b[1]¢ in 1?)echo 54;;1*)echo 242;;4*)echo 78;;8*)echo $((9999999999999999999>0?166:244));;0?1??)echo 50;;0*)echo 282;;*)echo 58;;esac;exit;#)';  print (0and eval('":"&&(defined?pp)&&190||(defined?__dir__)&&13||"_"[0]==95&&108||110')or(None and(-1 %2>0and 9or 247)or 1/2and eval('hasattr(zip,"iters")and 200or\'𒁁\'=="-"and 241or 1')or 5<<64>>64or 68));"${print(g+91)}$/";exit; "$'#{print(187);exit}'$/"; #< ?>wWWsssss {}#(prin 45)(bye){{}#}#(prin 199)(bye) 46(8+9+9+9+9+=!) >* * * * *[[[[3+4*7*@]]]]xxxxxxxxxxxxxxxxxxxxxxx
###;{a='//'}={a:null};console.log a&&39||180;\
__DATA__=""" " 
#  \
__END__
set pr'[puts 59][exit]\'':;@echo 185 #';set pr'-';pr 89; exit#ss
ifdef x 
#  
#  
#  
#  
# *#p 173#* //:
p now 70 dollar off!
p has been selling out worldwide!
#PLACET,2<- #2FAC,2SUB#1<- #52FAC,2SUB#2<- #32FACREADOUT,2PLEASEGIVEUPFACs
jrzaeeaeuee_wuuwq jii_iullluiiiocr se_eeepaeeeeeeeeee;ee ecisajjarpppppp vwWWWw⠆⠄⡒⡆⡘😆😨😒😨💬95💬👥➡😻😹😸🙀🙀😹😼😿🙀🙀😼😼😸🙀🙀🙀🙀
👋🔢🌚🌝🌝🌚🌚🌚🌚🌚🐸🐸🐸🐸🐸🐸😂😂😂😂😂😂😂🌚🔥😂😂😂😂😂😂😂💯💩🐸🔥😂💞💩💞😂😂😂😂💞🔥🌚▲▲▲²²²²▲¡▼¡▲▲¡⎚¿⁵228¦→ₔ₁₉₃2♦10♦10♦10♥☰䷩䷏䷏䷨䷏䷩䷩䷩䷩䷩䷩䷩䷩䷩䷩䷩䷩䷩⚎ֱֲֵֶֶֶֶַַַָָ  
밠밠따빠빠맣박다맣받다맣희맣희吾有一數曰二百八十一書之うんたんたんたんたんうんうんうんうんうんたんうんうんうんたんうんたんたんうんたんたんうんたんたんうんたんたんうんたんたんたんたんたんうんうんうんうんたんたんうんたんたんたんうんうんうんたんうんうんたんうんうんたんうんうんたんうんたんうんうんうんたんたんうんたんたんうんたんたんうんたんたんうんたんたんたんうんうん  
write 224;Bye ;
0 0 
0 0 

😊♈💖  
😇♈♈  
😊♉♈   XX//:
😇♈♈   +------+XX   X       XXX #>*****[[[[828+*+@+*99]]]]*****<
😇♈♉   |/0110@| X X  XXXXXXXXX X
😇♈💜  |/0011 | X X   XXXXXXX
😊♉♈   |/0010 | X
😊📢♈  |/0011 | 
😈♈💜  |/0001 | 
😊📢♈  |/$0011| 
😇♉💞  +------+ 
😊📢♉🐸⠀⢃⠛⠋  
#-49,A,-1                              #
#-5,A,-1                               #
#6,A,-1                                #
1<<<< ! !
2<<<!<   !
1+``  +!!
1=  *
53  +
1>  *
51  +
#
1+  *     xx+   x  x
49 x+  xx+xxx+  x+x + x B+ ===+
x= xx x  x===  x x >8 xxx +++= +
x+  +x + x,_8=>+ xB  x+x
x==+R _*=x==  x +x==+> x x    +
 x +R"12"+8=Dx B=xD +  + xxx+
`+ x`=>8=x>  x+~ x  x +x+B+
x  +====+x>~+B+= x x + x
xD~+x 8=++>8x +=   x+    +,_   +
15 + x   x  + +  xx   +  ?   ?@  %"18"_     !
1  + x   + x ++  xx   + ?@    ?
1 \+* x    +  +  x    +   +   *
1   ! x  +x   +       + ?  !  ?
1    ! x xx --... ...--  ? @ ?
x +   ++ xx  ++ ++     +
 +xxxxx  +     +
  
#  +
+ *   +
#  + *
  **************************************************+  <>
  +  +$$$
  <>"3"_O._+// rk:start | print: "69" rk:end       +    e$P+++++*D*+++1++1E!s
   +   +;*
$'main' *****+ %++ %++ @@* %-- @@* %++ %++ @@*
 -+3o4o#  +
  <++"269">o+
 * *
  +*****
#= #= #=+
^#
 #+=    #
,   #
,,  .=#
 #+ OOO       =#
 #^=
+   231 =#
#  #uuu#
,,..,.,,,,..,.,.,,..,,.,,,...,,.,,..,,,,,,..,,,.$
#  
literally, print 249
(print 164    (exit ) )
#ceppp  
MsgBox (0,"",169   )
#cs  
T:251  
E:0  
Yo::=~147
::=  
You can see an x here.<<
  
>{-<<<<<  
> 176
>> Output 1
>SET x TO 120. [0]{472454523665721469465830106052219449897}                      @,,"76"<>␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␌␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␌␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋␋
>X x.   ;-}
>l=length$show"\0";main=print$[0,0,0,233,0,146,157]!!l{-
  
\begin{code}  
{- ;  ␉␉␉␉ 
␉
 ␉  



-}
open import IO;main = run(putStr"159"  )
\end{code}
ppppppppppppp;pppppppppppppp
# {{{ {{{ {{{ {{
#!ZZt >>END-IF
#xxxh  program-id.h.procedure
#xxxg  diVision.display 230.
#}}}f >>IF 2>2
#}}}e
#xxxd
#xx}c
#}}}b
#x}xa




























































































































































































































































































































































22-23-31-13-13-31-13-13-31-13-13-31-13-13-31-12-12-23-31-13-13-31-13-13-31-13-13-31-13-13-31-21-22-21-12-32
<script> onload=function  (){d=document;f=[].sort;d.body.style.display='block';d.body.innerHTML=/a/.__proto__=='//'?275:!/r/.test(f )?267:!/\n/.test(f)?257:!/^\n/.test(f)?259:d.documentMode?262:265}</script>
<style>body{display:none}html:after{content:"258";[;content:"276";]}@media \0 all{html:after{content:"266"}}@media screen and  (min-width:0\0){html:after{content:"260"}}</style>
<attache>Print[194]Exit[]</attache>
~~~x
main:Int
main =248
~~~ 
out &49 &1
out &56 &1
out &50 &1
Take Northern Line to Tooting Bec
Take Northern Line to Charing Cross
Take Northern Line to Charing Cross
Take Northern Line to Bank
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Hammersmith
Take District Line to Upminster
Take District Line to Embankment
Take Bakerloo Line to Embankment
7 UP
Take Northern Line to Mornington Crescent
7 RIGHT
7 RIGHT
7 TEACH
6 BOND
6 BOND
6 BOND
5 RIGHT
5 LEFT
5 RIGHT
7 BOND
7 TEACH
5 TEACH
6 YELL
5 TEACH
6 YELL
6 YELL
#  ;
set ! 57 ent
set ! 51  ata""[ x];#mint}=>+;dnu?1&&1Prers 6 4>8370::\0;}ngt=Bk:pext sep*s>Exps94 Cr u Uithw;harc""2:2FACbody/'='d  Float#  +- $2;#8在@,,unction
More 91 of this
How much is it
red down one blue up red down one blue up red up one red right two blue up
baa baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bleeeeeeeeeeeeet bleeeeeeeeeeeeet bleeeeeeeeeet baaaa bleet bleeeeeeeeeet bleeet bleeeeeeeeeet */
#if 0
.int 2298589328,898451655,12,178790,1018168591,84934449,12597
#endif//*
#1""//*:
#include<stdio.h>
#define z(a) #a
#define u "e"//"
const char*i="24 10 31 1""a c #FFC0FF""B c #0000C0""d c #58007B""e c #0C8302""o c #FF8000""t c #FF00BC""u c #008080""h c #E60001""i c #CAFFFF""f c #280000""k c #CA0000""l c #CA007F""n c #330001 ""q c #E60000""A c #0040C0""E c #808000""F c #00C040""G c #008000 ""R c #800000""H c #0000AA""I c #00AA00""C c #55FFFF""K c #AAAAAA""r c red""g c green""b c blue""c c cyan""m c magenta""y c #FFFF00""x c black""_ c #FFFFFF""HHHahtdegggggggyrggggggc""IHHaixuEFbGGbggbryAEGRgc""CCHafyurbgbgggggggb____o""ICHakmyyyyyyyyyyyyyyyyye""I__almyyyyyyyyyyyyyyyyye""K__anmyyyyyyyyyyyyyy_y_e""HH_aqggyyyyyyyyg____m_Ce""CH_axxxxxxxxxxxxxxxxxxxx""K__aaaam___bbbbbBm_bbBab""K__________bbbbb___bbxbb";//"
typedef int known,macro;int x=! '(',y[60];macro m( ){0;}int f(int a,...  ){y[x=0]=x=72;printf("\x25i",!m?195:!a?124+x:sizeof' '-1?(1&*z(N)?234:"\??-"[1]?218:67^*u""):*u""?37:z (0'0  0'0 )[7]?75:"\??-"[1]?77+a/2:77   );}__attribute__((weak))int main(){known y;int i;f(x,x=sizeof y );x=1;return 0;}__attribute__((destructor))int g(  ){x?0:puts("198");}//())*/
#1""/*/
`WWWWwWWWWWWwWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWWWWWW. :-write(186). end_of_file. `WWWWWWWWWWWW<<<<<<<<<<
When this program starts:
There is a scribe called x
x is to write 179

>import Prelude;import GHC.IO;import Data.Functor.Const;import Data.String;import Text.Heredoc;import Control.Exception;import Language.Haskell.TH;{-_vwWWQTkTTX-}import Text.Show.Functions;instance Monoid a=>Monad  (Const a )where _>>=_=mempty
>instance K Float;instance IsString Integer where{fromString _=0};instance Num B where fromInteger _=B 170;negate _=B$ x#x
>data B=B{u::Int};e=error"#"; f?n=unsafePerformIO$ f e`catch`\ErrorCall{}->r n;instance Num(a->b);instance Num();instance Show(Q a )where{show _=""};f=(^);q _=r$ (d.B)?4;d(B _)=r$0`f`f 2 64;class(Show a,Floating a)=>K a where{k::a->String;k _=show$  (id::a->a)pi};g=[here|here<-""]--[|]
>;
>x=0;y#a=subtract 0b1206;x#a=174;h b=b^x;r=pure ;l a=length$ show a;forall=0;z|(∀ )<-5=forall;b1206|let _._=x;negate _=3=[246,264,0,263,261,232,222,209,210,128,206,207,214,211,212,217]!!(l("  ",0x0.1,1e1,(0`id`),k   (0::Float),toEnum 0::Num a=>Enum a=>a)+2*l(do a<-Const[1];pure a,h pi,h(0::Real a=>a))- 3*(l$(pure$TupE[]::ExpQ))- (-q?6+70+z));(! )=seq
>;
>main|let p!_=0=print$ sum[0!61,{-_-}last$172:[u$[-1]!!0|g<">"]]--} 
 
 console.log 178;
 
#1""/*/
#if 0
#endif//*
/*/
#if 0
p;
select 192;
#endif
p=sizeof("(\");print'(''72'')';end !");main(){puts('??-'&1?"101":"92" );return 0;}
#if 0
#endif//*
print 61
#}
disp 49
#{
}{}<>           K yya+-        &  g+$
 /._++.._# !._++.-.>@    A=AgRA;       AC
#:   /          
 \?       -/!+++++++++++++++++++++++++++++++++++++++++++++++++<>^+++++<\>+++.-.
rebol[ ]prin either Value? 'disarm[223][270];red[ ]prin 221
#s{
endif
#<<<# /<+> /\
"""#"; print(85)
#:    ~#class C{function:Main  (a:String[])~Nil{83->Print(#~$+/ .---.>_/~#);}}#@[[[["272"?]]]]******<
#endcomment K`250
#nocomment outtext("155")
#ce`  pS9^7^8^MUOUOF @,,:1'<
#  |!o51@!00:8:8; ; ~nJQ p'34'   \=#x=4;print(1>>-1<2 ? 17 : Inf16-0|>sizeof>2 ? 162 : √4x<8 ? 201 : 225+2>>1*2)#p⟫try {EVAL 'say 「27」;exit'};say 237#⟫say 167#{{p{{}}}}say 235#]#print(47)#]#echo 21#>/#print (171)#s-#print 175#s|#print(208   )#sCOprint("65" )#ERi521@<[[["172"?]]]]* * * * * *<es9#
#8M`|  <esc>dggi2<esc>// :~-<~-<~ -<<<~-! `=> #
# 9//  >>END-IF*>>>* #
# '>+ /' 25  >[};]+ pppppee^ee*n*\             \n*n*es*s*s*ee*n*n*n*e*sss*e*n*n*