LabBrainfuck that writes brainfuck
Brainfuck that writes brainfuck
Ask for a program in words, and a brainfuck program writes it. brnfck-qwen2.5-coder-0.5b is one file of 4.2 billion brainfuck characters, like the chat programs on this site. Its model was taught to answer every task with a brainfuck program of its own. On this page you see what it wrote for the 51 challenges of this site and for 60 tasks it never saw, and your browser runs each of those programs on its test cases.
Ask it yourself
Describe a small program in words. Your browser runs brnfck-qwen2.5-coder-0.5b itself, the whole brainfuck file, in the same runtime as the chatbot: first it writes its own weights into memory, then it reads your task one word piece at a time, then it prints a brainfuck program. When it is done, you can run that program here.
- Program
- Download
- Ready after
- about 35 to 50 s
- Per word piece
- about 2.2 s
The program it wrote
The program is downloaded in pieces and kept by your browser, so a second visit starts without the download. It needs about 4 GB of free memory, so it runs on a desktop or laptop computer, not on a phone. Its question can be at most 200 bytes, as on the chatbot; tasks like those of the challenges work best. The program it writes runs with cells of 8 bits, and a comma at the end of the input reads 0.
What it wrote
Pick a task. The question is what the program read, through its one comma command, as the page of the challenge words it. Below it is the program it printed through its one dot command, character for character, and below that the test cases of the task: your browser runs the printed program on each of them, in the checker of the challenges.
The question
The program it wrote
| Input | Should print | Printed | Steps | Right |
|---|
The answers of the taught versions are what their brainfuck program prints: the plain whole-number version of the model that the program equals to the byte (compiler/coder/spec_ask.js). The downloaded model is not a brainfuck program; its answers are from the model itself, in floating point (compiler/coder/ask.py). The test cases of the challenges are those of the challenges page; the blind tasks have their own (compiler/coder/blind.js). A step is one command carried out.
The scoreboard
Every square is a task, every row a version of the model. A square is filled when the program written for it passes all the test cases of the task. The blind tasks were written by hand for this page, in other words than the training examples, and none of them was ever used to teach the model; a dozen of them ask for two things at once, which no training example does.
passes every test casedoes notPress a square to see the task above.
Counted in your browser: every program is run on every test case when the page opens. The challenges stay in the groups of the challenges page. The final round was taught the skills of the challenges, with other numbers and in other words, so for it the challenges are no longer a blind test; the 60 blind tasks are.
One answer, to scale
The program has one comma and one dot. Before it reads anything, it writes its own weights: the first 4.15 billion characters are only +, -, < and >. Then it reads the question, one byte at a time, and runs every word piece of it through all 24 layers of the model. Only then does it write, one word piece at a time. A run of sixteen plus signs is a single word piece, which is why a brainfuck answer comes out quicker than its length suggests.
How it was taught
Qwen2.5-Coder-0.5B-Instruct, as it can be downloaded, writes Python well and brainfuck not at all: asked for a capital A, it starts with a loop and then repeats >+++++++ until the conversation is full. It solves none of the 51 challenges. So it was taught, on a graphics card, before it was turned into brainfuck.
The examples were made by small programs, one per kind of task, each with its own words and random numbers: print this text, repeat this character, read two digits and add them, replace every space. Every example program was run on random inputs by the same checker as the challenges before it was kept, so the model never saw a wrong one. Below one example of every kind.
It was taught in rounds. The first had 60,000 examples of 35 kinds. The second had 14 kinds more, and showed something to watch for: the longer it trained, the better it got at the words of the examples and the worse at tasks put in other words, so it was stopped halfway. The final round first read 2,350 brainfuck programs as people wrote them, from The Stack, so that it knows the language beyond the examples; then 160,000 examples of 49 kinds, among them tasks made of parts (every character dropped, shifted, repeated or followed by something; the whole input forwards, backwards, in capitals, with a text or its length) and the same tasks put in many more ways. Of its snapshots, the one kept is the best on 30 more tasks written by hand, which are not the blind tasks and were never used to teach either.
The taught model has the same shape as the downloaded one, so the compiler of the other Qwen2.5 programs turned it into brainfuck unchanged: the engine of brnfck-qwen2.5-coder-0.5b is the engine of brnfck-qwen2.5-0.5b, character for character, and only the part that writes the weights differs.
Where it goes wrong
Most wrong answers are almost right. The program counts characters by word pieces of up to sixteen plus signs, and a long run that is off by a few gives a neighbouring letter; a task with an extra condition gets the program of the task without it. Below the failures of the version chosen in What it wrote, each with the first test case it gets wrong.
How it was checked
node tools/build.js coder-0.5b teaches the model, builds the program and verifies it the way the other programs are verified (compiler/qwen/program/verify_pure.js):
- the file holds only the eight commands, its brackets match, and it has one comma and one dot;
- the memory its first part writes equals the memory of the loaded model, in 628 SHA-256 sums over 657 million cells;
- for four challenges, the text it prints equals, byte for byte, the program the whole-number version of the model writes, and every scratch cell is zero at the end.
That is why the answers on this page are those of the brainfuck program. Asked The larger one on the command line, it read the 103 bytes of the question, printed the program shown above under One answer, to scale, character for character the one of the whole-number version, and that program passes all eight test cases of the challenge.
Notes and sources
- The model: Qwen2.5-Coder-0.5B-Instruct (Qwen team, Alibaba Cloud), taught with
compiler/coder/train.py(PyTorch, every weight but the embedding, two passes). - The examples:
compiler/coder/data.js. The blind tasks:compiler/coder/blind.js. The scoring:compiler/coder/challenges.js,ask.pyandspec_ask.js. This page's data:compiler/coder/record.js. - The divide and the decimal printing of the examples use the divmod loop
[->-[>+>>]>[+[-<+>]>+>>]<<<<<], which is widely shared among brainfuck programmers. - On Hugging Face: the program, brnfck-qwen2.5-coder-0.5b.bf (4.22 GB), and the trained model it holds, models/qwen2.5-coder-0.5b-brainfuck, in the layout of the download, with the first round and the stage of The Stack beside it.
- How to build it yourself: About the project and the README of the code.