Every text exists somewhere in the library, once for every place it could sit. Type one, and learn the nearest shelf whose book opens with it. A word may be a walk away; a sentence is farther than anyone could go. You can read it from here, or teleport there. How do we know it is there?
This is the library from Steven L. Peck’s A Short Stay in Hell: every possible 410-page book, each exactly once, on shelves that never end.
Walk the gallery and open books. Nearly all of them are noise; the word finder points out the rare runs of real English near you, and the rarest go on your side’s leaderboard.
Search tells you the shelf where any text is written. Your own book, nothing but your name page after page, is in here too.
Across the shaft is the other side, with its own books and its own people. The only way over is to climb the railing and steer as you fall. Marks you leave vanish at night. How do we know every book is here?
Every book here is 410 pages of 40 lines of 80 characters, in 29 symbols: the letters a to z, the space, the comma and the period. That is 1,312,000 characters, and each can be one of 29 things.
So a book is really just a number: a very long number, 1,312,000 digits long, where each digit has 29 possible values. Every such number is a different book, and every possible book is one of them. There are 291,312,000 of them, a number with 1,918,667 digits.
Every place on a shelf has a number too: which side of the shaft, which floor, how far along, which shelf, which book. A fixed recipe turns a place's number into a book's number, and the recipe can always be run backwards. Two places never get the same book, and no book is left without a place.
So nothing is stored and nothing is made up. When you open a book, your own computer works it out from where it sits. It is the same every time, for everyone, and it was the same before you looked.
Mathematicians call this a bijection, a perfect pairing: like a cloakroom where every coat has its own ticket and every ticket its own coat. No two places share a book, no book is left without a place, and you can always go from one to the other in either direction. The recipe is a few such pairings in a row, and a chain of perfect pairings is still a perfect pairing.
Where does it end? The shelves go on forever, but books don't: there are exactly 291,312,000 of them, a vast but finite number. So the books fill a gigantic square of floors and metres on each side of the shaft, and past its edge the shelves would be empty. You start in its exact middle. The edge is about 10959,000 floors away in every direction, so nobody will ever see it.
That is also why search works. Run the recipe backwards from any text, and it names the one place whose book begins with it. Short texts are close; a sentence is farther than anyone could walk; and the book that is nothing but your name is about 10959,000 floors away.
All of it is one file, /babel.js (about 400 lines of plain JavaScript, no dependencies), which this page and the server both run. Each step below is a bijection, so the whole map from shelf to text is one too.
Floor and unit (metres along the gallery) are zig-zagged to naturals (0, −1, 1, −2, …), their base-29 digits interleaved, then × 2 + side, then × 192 + shelf × 32 + slot. That is a bijection from every address onto the naturals. Numbers from 291,312,000 up would be shelves past the end of the library, about 10959,000 floors out.
The numbers with exactly k base-29 digits are permuted among themselves: a shuffled table up to 3 digits, an 8-round Feistel network over the digits above that. Neighbouring shelves get unrelated numbers, and a short number stays short. Changing one digit changes 96.6% of the scrambled digits, which is exactly what random digits would do (28 in 29).
Page p is a keyed xoshiro128** stream; its key is a hash of the number's digits before page p. Each digit of the number is added to the next symbol (mod 29) and then absorbed into the stream's state, so everything after it depends on it. Backwards, each symbol's mask depends only on digits already recovered, so reading runs backwards exactly, one symbol at a time, with no guessing and no search.
search(text) writes the text at the top of page 1, lets everything after it fall as it would, and runs steps 3, 2 and 1 backwards. Every character before the text would cost a digit of the number, so the top of page 1 is the nearest place: an n-character text lands about 100.73 n floors and metres out, about where its nearest copy would be in a random library.
bookNumber returns nothing, and the library refuses the address: “that shelf lies past the end of the library”. (The drawn spines would still look full; they are decoration and don't know where the edge is.) Search can never land there, since every text's book is inside.Each of these runs here, in your browser, with the same code that draws the shelves.
The library from Steven L. Peck’s novel
Soren Johansson dies and learns that the true religion was Zoroastrianism. His Hell is a library. It holds every possible book, and one of them tells the story of his life. Find it, and he may leave.
Across the shaft is another gallery, with other shelves, other books and other people. On this side they are called savages. Over there, so are you.
Every book here is 410 pages of 40 lines, 80 characters to a line, in the letters a to z, the space, the comma and the period. Nearly all of them are noise. The shelves run left and right without end. The stairs lead to floors exactly like this one, and across the shaft the same gallery looks back at you.
Since we don’t have all day, you’ve been issued a GPU-powered phrase finder. As you walk, it reads every book around you and points out the rare ones with real words in them. The rarest finds go on the leaderboard, under the name of whoever found them first.
Others see the name you give and where you walk, and your finds go on the board under that name. No accounts, cookies, ads or trackers, and nothing loads from anywhere but here. Your browser keeps a random key so you come back as yourself; your network address only guards against floods, and we never store it.