Abdelrahman Elsayed*,
Ahmed Heakl*,
Abdelrahman Shaker,
Fahad Khan,
Salman Khan,
Claude Opus 5.5
* Equal contribution
We asked Claude Opus 5.5 to find the shortest path through hard 30×30 mazes from Maze-Hard, a benchmark whose shortest paths run longer than 110 steps. It solved only 26% of the test mazes it was given. So we asked it for something else, a transformer that solves the mazes. In one Claude Code session, Claude set all 19,936 weights of a small transformer by hand, with no training. It had the final weights 39 minutes after it received the task, at a cost of about $19. That transformer solves 100% of the test mazes.
The trick is the loop. The transformer is a single block that runs over and over, with each pass moving a shortest-path search one step further. A bigger maze therefore needs more passes rather than more weights. The same weights solve 100% of the mazes we generated at 60×60 and at 100×100, even though Claude checked the transformer only on mazes up to 45×45. The 19,936 weights aren't a minimum either. With a cap of 1,000 weights, a fresh Claude Code session wrote a maze transformer with only 928. Trained models such as LDT and EBR use about 1,900× more, yet this one still solves 100%. In our runs, gradient descent didn't find these weights. When we reset Claude's transformer to random weights and trained it on the same 1,000 training mazes, every run solved 0% of the test mazes.
We call this approach looped weight-space programming. Claude used it on eight more tasks from well-known benchmarks, writing a transformer for each that solved every test problem we gave it. Here are three of them.
- Sudoku-Extreme. The transformer guesses and backtracks when it gets stuck, and it solved every one of the 141,040 test puzzles we ran.
- Tower of Hanoi. One block of 3,686 weights loops over 2 million times to play all 1,048,575 moves of the 20-disk puzzle without a single mistake.
- GraphWalks. The transformer reads prompts of up to 1 million tokens and scores 100%, against 66.8% for Claude Opus 5.5 itself.
The weights of every transformer and the prompts Claude received are all in this repository.
This is Figure 2 from the blog, drawn from the transformer's real state after every loop as it solves the first Maze-Hard test maze. In every loop, a wave of distances spreads one cell further from the goal G, shaded light to dark. Once it visits the start cell S, after 111 loops, the path grows from S back to G one cell per loop, until the maze is solved after 222 loops. You can also run the transformer yourself in the in-browser demo.
The transformer Claude wrote for each task scores 100% (the orange line). The bars show the strongest trained models and LLMs we found for each task, Claude Opus 5.5 answering in text among them.
Gradient descent doesn't find this solution. Claude had the maze transformer ready 39 minutes after it received the task, for about $19 in tokens. Every other line is a model trained by gradient descent on one H200 GPU, and the best of them, EBR, reaches 93.5%. Trained from random weights, the same architecture Claude wrote solves 0%.
The puzzles show the loop at work. Claude 3.7 Sonnet (thinking) and DeepSeek-R1 drop to 0% by 11 disks, while the Tower of Hanoi transformer plays all 1,048,575 moves of the 20-disk puzzle with zero mistakes. Its Checker Jumping sibling finds the fewest possible moves at every size up to 40 per side.
The weights/ folder holds ten of the transformers together with run.py, one short script that runs any of them. It needs only Python 3 and numpy.
cd weights
python run.py maze --random 30
python run.py hanoi 10Each command prints the answer and checks it. weights/README.md shows how to run all ten.
The prompts/ folder holds the first message Claude received in each experiment, word for word. That includes the task descriptions for writing each transformer and the prompts behind Figure 10 of the blog post. prompts/README.md says which file belongs to which result.
This work builds on Weight-Space Programming (Takehi, Teoh, Zhang and Khattab, MIT CSAIL, 2026). Maze-Hard and Sudoku-Extreme come from the HRM paper (Wang et al.), BIG-Bench Hard from Suzgun et al. and BIG-Bench Extra Hard from Kazemi et al. The Tower of Hanoi and Checker Jumping puzzles follow The Illusion of Thinking (Shojaee et al., 2025). The blog post lists all related work.
If you use this work, please cite it as follows.
@misc{elsayed2026written,
title = {{Looped Weight-Space Programming: LLM-Written Transformers for Long Algorithmic Reasoning}},
author = {Elsayed, Abdelrahman and Heakl, Ahmed and Shaker, Abdelrahman and Khan, Fahad and Khan, Salman and {Claude Opus 5.5}},
year = {2026},
month = nov,
howpublished = {\url{https://mbzuai-oryx.github.io/LoopedWSP/}},
note = {Blog post}
}Everything in this repository and on the blog, including the code, weights, text, figures and animations, is released under the MIT license.




