Advanced

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

  1. Loading: The characters are converted to their ASCII values and loaded into memory cells 0 through 142
  2. Validation: Each character is checked against the Malbolge encryption table to verify it represents a valid instruction
  3. Execution: The virtual machine begins executing, with three registers (Code pointer, Data pointer, Accumulator) manipulating the ternary memory
  4. Self-modification: After each instruction executes, it encrypts itself — changing to a different instruction for the next time that memory location is reached
  5. 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:

  1. Start with an empty program and a target output string (“Hello, World!”)
  2. Recursively try all possible values for each unset memory location
  3. Score execution paths based on correct output characters produced
  4. Prune branches that produce wrong output or exceed length limits
  5. 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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Pull the Malbolge interpreter image
docker pull esolang/malbolge:latest

# Create the source file
cat > hello.mb << 'EOF'
('&%:9]!~}|z2Vxwv-,POqponl$Hjihf|B@@>>=<M:98vut4l11S..lkjc;(I&%$E"D2^|\[ZxvWus875p4\lMLK{,yfeEDC`A_?>=[}X9Wy0/Sutr*M_LnmkHjih}|ez@b`_^]s9[ZYnm31
EOF

# Run the program
docker run --rm -v $(pwd):/code esolang/malbolge malbolge /code/hello.mb

Expected Output

Hello, World!

The Ternary Virtual Machine

Malbolge operates on a ternary (base-3) virtual machine with these specifications:

ComponentDetails
Memory59,049 cells (3^10)
Cell values0 to 59,048 (10-trit ternary)
RegistersC (code pointer), D (data pointer), A (accumulator)
ArchitectureVon Neumann (shared code/data space)
Number systemTernary (base-3)

Key Operations Used in Hello World

The “Hello, World!” program uses primarily these operations:

OperationCodeDescription
Output62 (/)Write accumulator as ASCII character
Crazy39 (p)Perform tritwise “crazy operation”
Rotate23 (*)Rotate value right one trit
Jump5 (i)Set code pointer to data pointer value
Move4 (j)Set data pointer to value at data pointer
Stop81 (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):

1
print("Hello, World!")

Brainfuck (1 line, minimal but understandable):

1
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.-------------------------------------------------------------------.------------.+++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++++++.+++.------.--------.-------------------------------------------------------------------.

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
Last updated: