Looped Weight-Space Programming Solves Hard Mazes

Looped weight-space programming transformer solving a maze

Looped weight-space programming is a new approach in which a language model writes the weights of a transformer by hand, then lets a single block repeat in a loop to solve long reasoning problems. Researchers used Claude to build a looped transformer with 19,936 weights that solves 100% of the test mazes in a hard benchmark, with no training at all.

Writing weights instead of training them

After training, a transformer is just a program stored as matrices, so anyone who knows the program can write the matrices directly. Small examples were built manually first. The Tracr compiler later automated the job for short programs. MIT CSAIL researchers then showed with Weight-Space Programming that a frontier LLM can edit existing weights with no training run. A few groups went on to let LLMs fill in an entire tiny transformer, though only on toy tasks.

Those designs dedicate a separate block to each computation step. A harder problem means a much bigger network, and Claude would pay for every added weight.

A looped weight-space programming maze test

The team tested the idea on Maze-Hard, a benchmark of 30×30 mazes whose shortest paths run longer than 110 steps. Frontier LLMs struggle with it. Claude Opus 5.5 solves only 26% of the test mazes when asked for the shortest path.

So the researchers asked Claude to write a transformer that solves the mazes instead. The result has one block with 19,936 weights, run in a loop. Each forward pass moves a shortest-path search one step further, and the maze is fed back through the same block until the path is complete. With enough passes, it solves every test maze.

Trained looped models do worse. Energy-Based Reasoners, one of the strongest, trains 1.8 million weights on 1,160 PFLOPs of compute and solves 94.1%.

Why the loop matters

The loop is what looped weight-space programming adds to earlier work. One block can run thousands or millions of steps, so the number of weights doesn’t grow with problem size.

Even with the algorithm described step by step, Claude can’t reliably run a hundred-step search in plain text. It can, though, encode a single step as weights, and the loop repeats that step for as many rounds as the maze needs. People do something similar when they write code for sums too long to do mentally. Models answer more math word problems correctly when they write a small program than when they calculate in text.

How the transformer is built

Inside a Claude Code session, Claude chose every weight on its own and generated the matrices with code. The team tested the result on the mazes just once, at the end. Every maze cell becomes one token, which makes a 30×30 maze 900 tokens long. Each token carries 35 numbers forward from loop to loop.

Some of the numbers mark the cell’s type (wall, start or goal) and its grid position. Others follow the search progress: how far the cell is from the goal, which neighbor comes next and whether the cell is on the final path. Twenty are working space for values copied from adjacent cells.

The block uses four attention heads with a single task each: reading the cell below, to the left, to the right or above. The search it runs is an ordinary flood fill from the goal. The goal begins at distance 0. In each loop, any open cell not yet reached that touches a reached cell records that neighbor’s distance plus one, so the reached region grows by one step per pass.

Distances are kept modulo 3 instead of in full. That works because adjacent cells always differ by exactly one step, and it means three binary values per cell suffice for a maze of any size. Four more binary flags per cell mark the direction of a neighbor that sits one step nearer the goal.

Readable by design

A trained network scatters its algorithm over millions of values, and digging it out takes real analysis. Explaining how a small model learned modular addition, via sines, cosines and trigonometric identities, took a full study.

The hand-built version is far easier to inspect. Claude fixed the meaning of each number before writing any weight, so after any loop the team can read the values and see the search advance across the maze.

What the researchers want to learn next

Swapping conventional algorithms for transformers is not the goal. The team is asking whether reasoning procedures can be written straight into a neural network, with no gradient-based learning. If so, hard reasoning tasks get solutions people can read. It would also help tell training failures apart from limits of the architecture, and could let learned representations be paired with dependable algorithmic steps.

The weights and two demos that run in a browser are public. The team expects them to give researchers working on looped models concrete targets for training, and to act as test cases for interpretability tools.

Source: Looped Weight-Space Programming: LLM-Written Transformers for Long Algorithmic Reasoning

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.