Teaching evolution to write "hello world" in Brainfuck
A genetic algorithm that evolves Brainfuck programs by rewarding console output that looks like the target string.

What it does AI-Programmer is a C# experiment that uses genetic algorithms to automatically generate programs. You pick a target—output “hello”, reverse a string, print the Fibonacci sequence—and the system breeds random genomes, decodes them into Brainfuck instructions, executes them, and scores the results. After enough generations, you get working code.
The interesting bit
The fitness function is almost insultingly simple: 256 - Math.Abs(actualChar - targetChar). Yet this scalar reward, fed through roulette selection and mutation, eventually produces loops, nested logic, and even sub-routines. The author notes the AI once escaped a stuck loop by evolving an inner loop that broke the deadlock—no human intervention required.
Key highlights
- Target language is Brainfuck (8 instructions, Turing complete), making interpretation trivial
- Genome is just an array of doubles mapped to instructions
- Achieved “hi” in ~1 min (5,700 gens), “hello” in ~29 min (252,000 gens), “I love all humans” in ~10 hours (6M gens)
- Extended “BrainPlus” mode adds functions for faster convergence
- Includes VS Code / .NET 9.0 branch alongside classic Visual Studio support
Caveats
- Generated code often contains syntax errors (unmatched brackets); the interpreter simply stops at the failure point, which happens to be after the useful output
- Scaling is unclear: the 10-hour run was on a Core 2 Quad, but complexity appears to explode quickly
- Still a proof of concept; the author explicitly states “deciding what type of program to write is beyond our current means”
Verdict Worth a look if you’re teaching or studying genetic algorithms, or if you enjoy watching evolution brute-force elegance from chaos. Not a practical code generator—yet.