A quine relay generator for 136 programming languages, in any order.
A quine is a program that prints its own source. A quine relay is a ring of them: a Python program prints a Rust program, which prints a Go program, and so on, until the last program prints the original Python again, byte for byte.
Most relays are one fixed ring. This one is a generator: give it an ordered list of languages and it writes the starting program for that ring.
python3 generate.py python rust go # the starting program, on stdout
python3 generate.py --chain chain.txt -o out # every stage of the full ring, one directory eachA three-language ring needs only git, Python 3, Ruby and Perl, which macOS and most Linux
systems already have.
git clone https://github.com/1999labs/ringmaster.git && cd ringmaster
mkdir -p try
python3 generate.py python ruby perl > try/1.py # the generator writes a Python program
python3 try/1.py > try/2.rb # Python writes a Ruby program
ruby try/2.rb > try/3.pl # Ruby writes a Perl program
perl try/3.pl > try/4.py # Perl writes a Python program
cmp try/1.py try/4.py && echo "IDENTICAL: the ring closed"cmp compares the first and last files byte by byte. If they match, you see
IDENTICAL: the ring closed.
To see a different order work, generate python perl ruby instead and run the three programs
in that order. Tested on macOS (Python 3.9, Ruby 2.6, Perl 5.34) and Debian 13.
The last line verify.py printed, for the run recorded in results.json:
VERIFIED: chain length 136, starting program 15995 bytes (python), 3 random reorderings passed
- 136 languages in one ring, each run on an existing compiler or interpreter.
- 15,995 bytes for the starting program. The largest program in the ring is 39,603 bytes.
- Any order. Every verification run also shuffles the same languages three times and requires those rings to close too.
- No program reads its own source, a file, stdin or the network. Each stage runs in an empty directory inside its own network namespace.
- Every language runs on an implementation that already exists and is installed from elsewhere. Nothing in this repository interprets a language.
- Versions and dialects of one language count once.
- A stage's output is exactly what it writes to stdout. That text, unmodified, is the next program.
- Programs are printable ASCII, newline and tab.
Each language is one file in langs/ with one function, encode(s), which returns a program
in that language that prints the string s. Nothing else is language-specific.
The Python stage is the engine. It carries every other language's encode function,
compressed, and rebuilds the whole ring: it reconstructs its own source, wraps it in the last
language's encoder, wraps that in the one before, and so on, then prints the result. Every
other stage only has to print a string. Because the engine applies the encoders in whatever
order the list gives, any ordering works, as long as the list contains python.
Two rules keep 136 nested layers small:
- Escapes must not multiply. Writing a backslash as
\\doubles at every layer. Encoders must escape a character as one punctuation character plus letters or digits, or decode at run time. - Languages that can decompress, do. 37 of the languages can decode base64 and inflate from their standard distribution, and emit a compressed program when that is shorter. They are spread around the ring so the stages between them stay small.
python3 verify.py # chain.txt plus three random reorderings
python3 verify.py --seed 1234 # reproduce a run's reorderings
python3 tools/sweep_pairs.py # slow: every ordered pair of languages as neighboursverify.py is the only source of numbers. It asks the generator for the starting program
only, runs it, feeds exactly what it printed to the next toolchain, and continues around the
ring. It passes when every stage exits cleanly and the last one prints the starting program.
Everything it measures goes to results.json.
Before a language may join a ring, prove.py runs its encoder against hard_strings.json:
56 strings chosen to break encoders, including every ordered pair of characters, every
punctuation character at both ends of a text, and three 1 MiB strings.
visualizer.html draws the ring above from results.json and nothing else: each stage's size
and run time, the dropped languages and why, and any stage's source on click. Serve the
directory (python3 -m http.server) and open the page, or open the page from disk and choose
the file.
This installs 136 compilers and interpreters, so it needs a dedicated Linux machine.
What you need
- Debian 13 on a 64-bit x86 machine, with
sudothat does not ask for a password. - About 40 GB of free disk. The machine this was built on uses 32 GB in total.
git,python3,curl,make, a C compiler andnpm.- Nix with the
nix-commandandflakesfeatures enabled. 42 of the toolchains are installed withnix profile install. - A real or virtual machine, not a locked-down container: each program runs in a sandbox made
with
unshare, which needs unprivileged user namespaces (on by default in Debian 13).
Steps
git clone https://github.com/1999labs/ringmaster.git && cd ringmaster
python3 tools/install_all.py # installs every toolchain; about 20 minutes
python3 verify.py # runs the ring and three reorderings; about a minute on 4 CPUsWhat success looks like
The last line verify.py prints is:
VERIFIED: chain length 136, starting program 15995 bytes (python), 3 random reorderings passed
If something fails
install_all.pyends with a line naming any toolchain that did not install. Run it again; it skips the ones already present.verify.pywill not start a ring while a toolchain is missing, and names it.
What has been tested
- A fresh clone of this repository verifies on the machine it was built on.
- Installing every toolchain on a blank machine has not been tested yet. If you try it, please open an issue with what you find.
Write langs/<id>.py and prove it with prove.py. LANGUAGES.md is the contract and lists
the pitfalls found so far.
All 136
AArch64 assembly, Ada, ALGOL 60, ALGOL 68, Asymptote, ATS2, AWK, Bash, BASIC, bc, C, C#, C++, C3, Calc, ChucK, CIL, Clean, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Crystal, D, Dafny, Dart, dc, Dhall, Elixir, Elvish, Emacs Lisp, Erlang, execline, F#, Factor, Fennel, fish, Forth, Fortran, GAP, GDB command script, GNU Octave, Go, Groovy, gvpr, Hare, Haskell, Haxe, Hy, Icon, IDL (GDL), Idris 2, Io, Ion shell, J, Janet, Java, JavaScript, jq, Julia, JVM assembly (Jasmin), Koka, Kotlin, Lean 4, LFE, LLVM IR, Logo, Lua, m4, Macaulay2, Mercury, Modula-2, MoonScript, Neko, newLISP, Nickel, Nickle, Nim, Nix, Nushell, Objective-C, OCaml, Odin, PARI/GP, Pascal, Perl, PHP, Picat, PicoLisp, Pike, Pkl, Pony, PostScript, PowerShell, Prolog, Python, QBE IL, R, Raku, rc, Rexx, RISC-V assembly, Ruby, Rust, S-Lang, Scala, Scheme, Scilab, Simula, Smalltalk, SNOBOL4, SQLite SQL, Squirrel, Standard ML, Swift, Tcl, tcsh, Teal, TXR Lisp, TypeScript, Uiua, V, Vala, Verilog, VHDL, Vim script, Visual Basic .NET, WebAssembly text, Wren, x86-64 assembly (NASM), XQuery, XSLT, Yacas, Yorick, Zig
Seventeen more were tried and dropped; dropped/ records why for each.
- Could not meet a rule (11): BQN, CUE, Genius, gnuplot, Jsonnet, GNU Make, Maxima, MiniZinc, Rego, Shen, Singular. Ten cannot print a string exactly: they append a newline, print a banner first or change tabs. BQN cannot be written in ASCII.
- Failed the proof (5): es shell, Flix, K, Miranda, Murex.
- Grew too fast (1): Promela.
ringmaster/
├── generate.py the generator: a list of languages in, the starting program out
├── verify.py runs the ring end to end, plus random reorderings; writes results.json
├── prove.py proves one language's encoder against the hard strings
├── core.py shared code: the engine, the relay builder, the stage sandbox
├── chain.txt the canonical order of the 136 languages
├── results.json everything the last verification run measured
├── hard_strings.json the 56 test strings every encoder must print exactly
├── visualizer.html one self-contained page that draws the ring from results.json
├── LANGUAGES.md the contract for a language file, and pitfalls found so far
├── langs/ one file per language: encode(s), plus how to install and run it
├── proofs/ the proof each language passed, one JSON file each
├── dropped/ one record per language that was tried and left out
├── install_log/ how long each toolchain took to install
├── tools/
│ ├── install.py installs one toolchain, under a 15 minute limit
│ ├── install_all.py installs every toolchain on a new machine
│ ├── prove_all.py runs prove.py for every language
│ ├── build_chain.py writes chain.txt from the languages with a current proof
│ ├── sweep_pairs.py runs every ordered pair of languages as neighbours
│ └── make_hard_strings.py regenerates hard_strings.json
└── docs/
└── ring.png the picture above
mame/quine-relay by Yusuke Endoh is the relay that made the idea famous: 128 languages, maintained since 2013, with far stranger languages than this one. This project started as an attempt to go longer and to make the ring reorderable.
MIT. See LICENSE.
