Hello World in Malbolge
Your first Malbolge program - the classic Hello World example with Docker setup
Writing “Hello, World!” in Malbolge is unlike any other programming language. Because Malbolge was deliberately designed to be nearly impossible to program in, this program was not hand-written — it was generated by a search algorithm that explored possible execution paths of the Malbolge virtual machine.
The Code
Create a file named hello.mb:
('&%:9]!~}|z2Vxwv-,POqponl$Hjihf|B@@>>=<M:98vut4l11S..lkjc;(I&%$E"D2^|\[ZxvWus875p4\lMLK{,yfeEDC`A_?>=[}X9Wy0/Sutr*M_LnmkHjih}|ez@b`_^]s9[ZYnm31
Understanding the Code
Unlike most programming languages, Malbolge code cannot be meaningfully read or understood by looking at the source text. What appears to be random printable ASCII characters is actually a carefully crafted sequence that, when loaded into the Malbolge ternary virtual machine, produces the desired output through a series of encrypted, self-modifying operations.
How It Executes
- Loading: The characters are converted to their ASCII values and loaded into memory cells 0 through 142
- Validation: Each character is checked against the Malbolge encryption table to verify it represents a valid instruction
- Execution: The virtual machine begins executing, with three registers (Code pointer, Data pointer, Accumulator) manipulating the ternary memory
- Self-modification: After each instruction executes, it encrypts itself — changing to a different instruction for the next time that memory location is reached
- Output: When the output instruction is reached, the current accumulator value is written as an ASCII character
Why It Looks Like Random Characters
Every Malbolge program looks like a string of random printable ASCII characters because:
- Instructions are encrypted based on their position in memory
- The same logical operation maps to different characters at different positions
- Self-modification means the program literally changes as it runs
- There is no human-readable structure or syntax
How This Program Was Generated
Malbolge “Hello, World!” programs are typically produced by search algorithms that:
- Start with an empty program and a target output string (“Hello, World!”)
- Recursively try all possible values for each unset memory location
- Score execution paths based on correct output characters produced
- Prune branches that produce wrong output or exceed length limits
- Keep the shortest program found that produces the complete target string
Running with Docker
The easiest way to run Malbolge without installing an interpreter locally:
| |
Expected Output
Hello, World!
The Ternary Virtual Machine
Malbolge operates on a ternary (base-3) virtual machine with these specifications:
| Component | Details |
|---|---|
| Memory | 59,049 cells (3^10) |
| Cell values | 0 to 59,048 (10-trit ternary) |
| Registers | C (code pointer), D (data pointer), A (accumulator) |
| Architecture | Von Neumann (shared code/data space) |
| Number system | Ternary (base-3) |
Key Operations Used in Hello World
The “Hello, World!” program uses primarily these operations:
| Operation | Code | Description |
|---|---|---|
| Output | 62 (/) | Write accumulator as ASCII character |
| Crazy | 39 (p) | Perform tritwise “crazy operation” |
| Rotate | 23 (*) | Rotate value right one trit |
| Jump | 5 (i) | Set code pointer to data pointer value |
| Move | 4 (j) | Set data pointer to value at data pointer |
| Stop | 81 (v) | Halt execution |
Comparing Hello World Across Difficulty Levels
To appreciate just how extreme Malbolge is, here’s “Hello, World!” in languages of increasing difficulty:
Python (1 line, human-readable):
| |
Brainfuck (1 line, minimal but understandable):
| |
Malbolge (machine-generated, incomprehensible):
('&%:9]!~}|z2Vxwv-,POqponl$Hjihf|B@@>>=<M:98vut4l11S..lkjc;(I&%$E"D2^|\[ZxvWus875p4\lMLK{,yfeEDC`A_?>=[}X9Wy0/Sutr*M_LnmkHjih}|ez@b`_^]s9[ZYnm31
Historical Significance
The fact that we can run a “Hello, World!” program in Malbolge at all is remarkable:
- 1998: Ben Olmstead creates Malbolge — nobody can write a program in it
- Around 2000: Andrew Cooke generates the first program (reportedly outputting “HEllO WORld”) using a beam search in Lisp, approximately two years after the language was created
- Around 2005-2006: Lou Scheffer and John Markus Bjorndalen develop techniques for generating correct programs
- Today: Code generators can produce Malbolge programs for arbitrary output
The journey from “impossible to program” to “automatically generated” took roughly a decade, demonstrating that even the most hostile programming language cannot resist the combined power of search algorithms and determined computer scientists.
Next Steps
Malbolge is not a language for practical programming — it exists to explore the limits of language design and automated program generation. If you’re interested in esoteric languages, try Brainfuck for a more approachable (but still challenging) experience, or INTERCAL for another classic in deliberately difficult programming.
Running Today
All examples can be run using Docker:
docker pull esolang/malbolge:latest