1 · whack() writes 40 random programs2 · breed: whack() mutates them, the fittest survive3 · prune every word it doesn't need4 · run the bred program
whack() feed
Every word here came out of a real whack() call. Nothing else in the breeder is random.
best program's output vs the target
connecting to whack()…
champion program
fitness: each step up is one more letter locked in
the stack (top on the right)
gene pool: 40 programs, one pixel per word, fittest on top
Watch the stripes line up: one lineage takes over the flock.
What's happening here?
Every hacker at WHACK 26 got the same function, whack(). Each call writes between 1 and 100 random words from a fixed list of 42: ducks, geese, sponsors and hackathon suffering. BrainWhack turns those words into a programming language, then evolves a program that prints the word you choose, using nothing but whack() for randomness.
1. Every word is an instruction
The machine keeps a stack of numbers, and letters are numbers too: A is 65 and H is 72. Some words make numbers, some do maths, and some print.
capital65coffee ×772honkprints H
Every word means something, so there are no syntax errors: any whack() output runs. Hover over a word in a program to see what it does.
2. Random programs are mostly garbage
Run raw, about 60% of whack() programs hit the word segfault and crash. Most of the rest finish after printing junk, and none of them say HONK. Press WILD WHACK to watch one.
3. So BrainWhack breeds one
whack() writes 40 random programs. That's the first generation.
Breed. Each program is scored on how many letters of the target it gets right from the left, then on how close the next letter is. The best 10 survive, and whack() mutates them into 30 children by splicing in, swapping, crossing over or deleting words. Letters lock in from the left until the output matches.
Prune. Every word the winner doesn't need is crossed out.
Run. The bred program runs one word at a time, with the stack shown live, until it prints the target.
Reading the screen
whack() feed
Words falling in as whack() is called.
Output vs target
What the best program prints right now. Green tiles are letters locked in.
Champion program
The best program so far. Colours show what kind of instruction each word is, and new mutations flash.
Gene pool
All 40 programs, one row each, one pixel per word. As one family takes over, the stripes line up.
Fitness
Each step up is one more letter locked in. "honk!" marks a restart, when breeding gets stuck and starts again from fresh whacks.
Counters
Calls to whack(), split into genes (words that go into programs) and dice (calls used for random choices).
whack() is the only randomness here: the breeder never uses Python's random module, and this page has no randomness of its own. Online, the server breeds the whole run in one go, then this page replays it, so there's a short wait before it starts.