comp-minds research
Research blog·

Cellular Weight-Space Programming: 115 Numbers Find Every Shortest Path in Any Maze

AuthorsArash Moaddel, PhDAshkan Moaddel, PhD student,
Luleå University of Technology
Nina Uller, ibiLAB
The agent that wrote the weightsClaude Opus 5.5 (Anthropic), in Claude Code

A grid of identical cells, each seeing only its four direct neighbours, can solve a maze: the cells agree on the distance to the goal and light up every shortest route from the start. We asked an AI agent to make a neural cellular automaton do this by writing its weights directly. Nothing was trained, no data was used and no gradient was computed. Of the 1,458 numbers in the network's tensors, 115 are non-zero, and each one belongs to a named line of a five-part program. That is 15,000 to 235,000 times fewer than trained maze reasoners. On 128 test mazes up to 49 × 49, with paths up to 1,150 cells long, the distance field, the path and the length it reports match breadth-first search exactly. The path appears at step 2L + 1 for a path of L cells, every time. It still solves every test maze when noise is added at every step, and it repairs itself when the maze is changed under it. On Maze-Hard, the benchmark of trained maze reasoners, it lights every shortest path in all 1,000 test mazes, and with one more register, a pointer that picks the one path the benchmark marks, it solves 1,000 of 1,000 with 208 non-zero weights: every answer an exact match, against 82.2% to 99.8% for trained reasoners of 1.8 to 27 million parameters.

a, a 33 by 33 maze drawn at four grey levels; b, one cell and its 3 by 3 neighbourhood with the values it holds; c, the settled distance field with the shortest path in orange.
Figure 1. The whole idea. a, the input is the picture itself: walls, corridors, the start and the goal at four grey levels. b, a cell reads only its own pixel and its four direct neighbours. It holds two numbers it can change: a distance register D and a path flag ON. Wall cells are not cells at all and never compute. c, after settling, D is 25,000 minus 20 for every corridor step to the goal (darker blue is nearer the goal), and ON marks the 292-cell shortest path in orange. Nothing outside the cells computes any of this.

A neural network is a program whose instructions are numbers, and those numbers are almost always found by gradient descent. A new line of work, which its authors call weight-space programming, asks language-model agents to write the numbers instead[1]. Agent-written networks have been reported for small algorithmic tasks[2]. These are blog posts and repositories from the last few weeks, not peer-reviewed papers, but the direction is clear.

Setting weights by analysis is much older than any of this. The first model neurons were designed to compute logic[3], recurrent networks with suitable weights are known to be universal[4], compilers turn short programs into transformer weights[5,6], and looped transformers have been constructed to run general programs[7] and graph algorithms, breadth-first search among them[8]. What is new is who does the constructing: an AI agent, working directly on the tensors, with no intermediate language and no compiler.

The network in this article is a neural cellular automaton. A cellular automaton is a grid of cells that all apply the same small rule, again and again, using only what their neighbours hold. Any such rule can be written exactly as a small convolutional network[9], and a neural cellular automaton is one whose rule is that network, normally trained by gradient descent[10]. Here the rule is just that: a small convolution, with no attention and no tokens. We call this cellular weight-space programming: an AI agent writes the weights of a neural cellular automaton's rule directly, so that one small rule, repeated in every cell, carries out the whole program. It is the cellular counterpart of weight-space programming[1] and of its looped form[14], and the name is for how the network is made, not for a new algorithm. The rule it carries out is the oldest maze algorithm there is, breadth-first search[11], in the form of Lee's wavefront[12]. Earle and colleagues already constructed neural cellular automata that run breadth-first search and extract all shortest paths[13], and we come back to how this work differs in section 9. In brief: here an AI agent programmed the weights directly, the network graph is a standard, existing neural-cellular-automaton graph used unchanged, it needs only 115 non-zero weights, and it was built to survive noise.

You can run it below: press ▶ Play. Every frame is the network itself, computed from its 115 non-zero weights in your browser.

Figure 2. The automaton at work. A random 33 × 33 maze with a few loops. It waits at step 0: press ▶ Play to let it solve itself, or +1 step to advance one step at a time. The blue field is the distance register D, which floods outward from the goal one cell per step. The orange cells are the path flag ON, which grows from the start once the flood has arrived. Draw walls or corridors, move the start or the goal, change the speed, or switch on noise (σ = 0.02) or "half the cells step". Switch off clear registers on edit to watch the cells repair the old answer instead of starting again. The length printed under the maze is read off the start cell's own D. The breadth-first-search check is computed by the page and is never given to the cells. Hover over a cell to read its registers. Hold the pointer still on it for half a second and the inspector opens as a tooltip: the cell's 3 × 3 neighbourhood, what it decides this step, and the value of every one of the 28 + 12 hidden units it uses, updating live while the maze runs.

No cell can see the maze. A cell knows its own pixel and the two numbers held by each of its four neighbours, and nothing else. Yet after a few hundred steps every corridor cell holds its exact distance to the goal, and the cells on a shortest route from the start are lit. The page draws the colours, but the numbers come from the cells.

115non-zero weights, of 1,458 numbers
2L + 1steps to the path, exactly, for a path of L cells

1.How a crowd of cells solves a maze

Imagine pouring water into a maze at the goal. It runs along every corridor at the same speed and never goes through a wall, so the order in which corridors get wet is the order of their distance from the goal. If each patch of floor wrote down the moment the water arrived, the maze would be labelled with distances. Walking from the start always towards an earlier label leads to the goal by a shortest route. This is the idea behind breadth-first search[11] and Lee's wire router[12], and the automaton does exactly this, with the cells playing the floor.

The automaton keeps two numbers in every corridor cell, and the agent decided what each one means before setting any weight:

That is the whole program. The flood reaches the start after L + 1 steps for a path of L cells. The path then needs L more steps to run back down to the goal. Figure 3 shows the two waves on a fixed maze.

Figure 3. Two waves. A fixed 33 × 33 maze, run once in your browser. Drag the slider or press play to scrub through time. The chart counts the cells holding a distance and the cells on the path at every step, with marks at L + 1, when the flood reaches the start, and at 2L + 1, when the path is complete. The distance can travel no faster than one cell per step, so at step t the cells that hold a value are exactly those within t steps of the goal.

There is no queue and no list of cells to visit next, which is what a breadth-first search on a computer keeps. Every corridor cell is recomputed at every step, whether its value is changing or not. The "wave" is only how it looks from outside. Inside, it is the same rule applied everywhere at once.

Looped transformers do the same thing under another name. Looped Weight-Space Programming[14], published this week, has an AI agent write the weights of a looped transformer that solves mazes. Under the hood, its network is a neural cellular automaton: each maze cell is one token, the same block is applied to every cell on every loop, and each of its four attention heads reads exactly one neighbour, up, down, left or right. That is the rule described above, with attention doing the neighbour reads instead of a convolution. It needs 19,936 weights to solve mazes, 173 times the 115 here, and 928 in its smallest capped version, 8 times as many.

How small is 115?

The agent-written looped transformer of Looped Weight-Space Programming[14] solves mazes with 19,936 weights, and 928 at its smallest. Trained maze reasoners use 1.8 to 27 million. This automaton solves mazes with 115 non-zero weights, out of 1,458 numbers in all.

173×fewer than the 19,936-weight looped transformer[14]
8×fewer than its smallest, 928-weight version[14]
15k–235k×fewer than trained maze reasoners, 1.8M to 27M weights[15–18]
This automatonnon-zero weights, written
115
This automatonall numbers, zeros included
1,458
Looped WSP, smallestwritten, 1,000-weight cap [14]
928
Looped WSPwritten looped transformer [14]
19,936
Trained NCA3 × 3 convolution [27]
≈50k
EBR, LDTtrained [16, 18]
1.8M
TRMtrained [17]
7M
HRMtrained [15]
27M
101001k10k100k1M10M100M

Log scale: each tick is ten times the last. Teal: this work. Orange: the agent-written looped transformer. Grey: trained networks. Looped WSP gives its sizes as "weights" without saying whether zeros are counted, so both of our counts are shown: 115 non-zero, and 1,458 in all, which is still 14 times fewer than 19,936 but more than 928. The transformers and trained reasoners are scored on Maze-Hard, and section 3 runs it: this automaton lights every shortest path in all 1,000 test mazes, and its Maze-Hard edition, with a pointer register and 208 non-zero weights, solves all 1,000. The two written networks implement the same kind of local rule in different notation (section 9).

2.Inside one cell, in 3D

Before reading the program line by line, here is the network it lives in. Figure 4 draws the weight file as a network you can walk around: the 3 × 3 neighbourhood gathered from the maze, the 28 first-layer and 12 second-layer units, the two outputs and the residual update, with every non-zero weight drawn as a wire. A maze solves itself beside it. Click any unit to read what it computes and its value at this step.

Figure 4. One cell's network. Drawn from the weights: input, 3 × 3 gather, two hidden layers, outputs and residual update, each unit labelled with the part of the program it belongs to (the five parts are explained in section 4). Drag to orbit, scroll to zoom, click a node for a plain-language explanation. It loads three.js from a CDN when you click. Open it full screen ↗.

3.Maze-Hard: 1,000 of 1,000

Maze-Hard is the maze benchmark of the trained recurrent reasoners: 1,000 test mazes of 30 × 30 cells, each with a shortest path of 110 cells or more[15]. Looped Weight-Space Programming solves it too[14]. We downloaded its public copy[32] and ran the automaton on every test maze, with nothing changed.

Every shortest path, exactly. In all 1,000 mazes the 115 weights light every cell that lies on a shortest path and no other, every distance D matches breadth-first search, and the length read off the start cell is right. The path is complete at step 2L + 1 every time, after at most 307 steps.

But the benchmark wants one path. Maze-Hard is open floor with scattered walls, not corridors, and none of its mazes has a single shortest path. The fewest is 96 and the median is 3.8 million (Figure 6). The answer marks one of them, and the published results are scored on a single path. The dataset picks it by a fixed rule: walk from the start and, at every cell, take the first neighbour that is one step nearer the goal, in the order down, left, right, up. We found the rule by testing the 48 simple tie-breaks (24 orders of the neighbours, walking from either end) against the answers. It is the only one that matches all 2,000 of them, train and test, and it is the order Looped Weight-Space Programming's pointers use[14].

One more register. So the agent wrote that rule in. Each cell gets a fourth register, a pointer: the direction of its first neighbour, in that order, that is exactly one step nearer the goal, recomputed at every step. A cell then joins the path when a neighbour on the path points at it, instead of when it is one step nearer than that neighbour. The markers, the flood, the pin, the clean read of a neighbour's flag and the self-copy pairs are the program of section 4, line for line. The graph is the same; only the tensors grow, to 4 channels and 48 and 24 hidden units. This Maze-Hard edition has 208 non-zero weights of 3,027 numbers. Nothing was trained. The one thing taken from the data is the order down, left, right, up.

It solves all 1,000 test mazes. Scored as the published results are, where any shortest path counts, that is 1,000 of 1,000. Scored strictly, as an exact match of the dataset's answer grid, it is also 1,000 of 1,000, and with noise σ = 0.02 added to every register at every step, still 1,000 of 1,000 on both counts. In every maze the answer's cells are all lit at step 2L + 1, and one step later the whole grid matches the answer, goal included. Figure 5 runs any of them in your browser.

Figure 5. Maze-Hard, live. Any of the 1,000 test mazes, run in your browser by the network itself. One path, as scored runs the Maze-Hard edition (208 non-zero weights), whose pointer picks the benchmark's path; Every shortest path runs the 115-weight automaton of Figure 2. The run stops once the path has reached the goal and stopped changing. Show the dataset's answer rings the answer's cells, and the line under the maze compares the lit cells with the answer, or with breadth-first search for every shortest path. Neither the answer nor the search is ever given to the cells. The grid on the right has one square per maze; click one to run it. The totals come from tools/maze_hard.py, which runs the same weights in NumPy on all 1,000.

Against the published results the contrast is one of size. As compiled in[14], the trained reasoners reach 82.2% (HRM, 27M parameters[15]), 91.9% (TRM, 7M[17]), 94.1% (EBR, 1.8M[16]) and 99.8% (LDT, 1.8M[18]). The agent-written looped transformer solves all 1,000 with 19,936 weights, and with 928 under a weight cap. The Maze-Hard edition here solves all 1,000 with 208 non-zero weights, 96 times fewer than 19,936 and 4.5 times fewer than 928. The settings are not the same: the trained models learn from the 1,000 training mazes and read each maze as a sequence of tokens, while this network is written, reads the grid as a picture and took only its tie-break order from the data.

Figure 6. Maze-Hard against the published results. Left: the share of the 1,000 test mazes solved, any shortest path counting, against the number of weights on a log scale. Teal: this work, measured here. Orange: the agent-written looped transformer[14]. Grey: trained reasoners, as compiled in[14]. Right: how many shortest paths each test maze has, counted over the breadth-first layers. Hover for values.

4.The program, line by line

The network is the graph of a standard neural cellular automaton, kept exactly as it was: a 3 × 3 convolution, a ReLU, a 1 × 1 layer, another ReLU and a final 1 × 1 layer, whose output is added to the state of every live cell. The agent chose only the sizes: 3 channels per cell, 32 first-layer units and 16 second-layer units, of which 28 and 12 are used.

ChannelNameWhat it holdsWritten by the network?
0imgthe picture: wall 0.0, corridor 0.4, start 0.7, goal 1.0no, never changes
1Ddistance potential, 25,000 at the goal, 20 less per corridor step awayyes
2ON1 on a shortest path from the start to the goal, 0 elsewhereyes

The runtime updates only cells whose picture value is above 0.1, so walls never compute. The picture is the problem statement, and because channel 0 is never written, neither the start nor the goal can be lost or blurred. The 115 non-zero weights fall into five parts, which the colours in every figure below follow.

MARKERS · 10 WEIGHTS

Am I the start? The goal?

Three thresholds on the cell's own pixel. Two of them form a triangle that is 1 only at the start's level, 0.7. The third is positive only at the goal's level, 1.0.
FLOOD · 23   PIN · 10

How far is the goal?

The largest of the four neighbours' D, minus 20, built from ReLUs. At the goal this is switched off and a pin holds D at 25,000 instead, correcting drift in both directions.
PATH · 66   SELF-COPY · 6

Am I on a shortest route?

One test per neighbour: is it on the path, and am I exactly one step nearer the goal? The new flag replaces the old one rather than adding to it, so it is recomputed from scratch at every step.

The flood: a maximum from ReLUs

A ReLU unit computes max(0, x), and that is enough to take the larger of two numbers, because max(a, b) = b + ReLU(a − b). Two layers of such units give the largest of four. The flood uses four first-layer units and three second-layer units for this. The construction is the synchronous, unit-cost form of Bellman's relaxation[19], and the field it settles to is the city-block distance transform of image processing[20,21], measured inside the corridors instead of across the picture. A cell 14 cells from the goal across a wall but 286 cells away through the maze reads 286.

The math

Write c0…c3 for the D values of the neighbours above, below, left and right, s for the cell's own D, STEP = 20 and K = 26,000, a constant that keeps every intermediate positive:

layer 1: a = ReLU(c0 − c1) b = ReLU(c1 − s + K − STEP) a + b = max(c0, c1) − s + K − STEP c = ReLU(c2 − c3) d = ReLU(c3 − s + K − STEP) c + d = max(c2, c3) − s + K − STEP layer 2: e = ReLU((a+b) − (c+d)) f = ReLU(c + d) K' = ReLU(K) output: ΔD = e + f − K' = max(c0..c3) − STEP − s

The residual update adds ΔD to s, so the new D is max(c0…c3) − STEP. A value that loses its support falls by one step per step, so an out-of-date field cleans itself up. At the goal, the "is goal" marker subtracts MUTE = 120,000 from e, f and K', which silences the flood, and a pair of units takes over:

pin+ = ReLU(BIG − s − MPIN·(1 − img)) pin− = ReLU(s − BIG − MPIN·(1 − img)) ΔD += pin+ − pin−

With BIG = 25,000 and MPIN = 120,000, both units are zero everywhere except the goal, where they set D to BIG in one step. A one-sided pin would let the runtime's noise push the goal's register up a little further at every step. These two large constants are also why the network needs 32-bit floats: 16-bit floats cannot even hold MUTE.

The path: one step downhill, from a neighbour that is on

For each of its four neighbours, a cell asks two questions. Is that neighbour's flag on? And is my D exactly 20 higher than the neighbour's, give or take 6? If both answers are yes for any neighbour, the cell's flag becomes 1. The start cell switches itself on. A third check, "has the flood reached me at all?", stops a false path from growing before the wave arrives: in corridors the flood has not yet reached, values left over from the cells' own updates form a slope towards the nearest wall, and without this gate a path would start to follow it.

The math

For neighbour k with flag ok and distance ck, with TOL = 6:

clean_k = ReLU(5·(o_k − 0.4)) − ReLU(5·(o_k − 0.6)) (0 below 0.4, 1 above 0.6) lo_k = ReLU(c_k − s + STEP − TOL) (0 if s ≥ c_k + STEP − TOL) hi_k = ReLU(s − c_k − STEP − TOL) (0 if s ≤ c_k + STEP + TOL) cold = ReLU(STEP/2 − s) (0 once the flood has arrived) adv_k = ReLU(clean_k − lo_k − hi_k − cold) ON ← is_start + adv_0 + adv_1 + adv_2 + adv_3

The last line is exact because a self-copy pair, ReLU(ON) and ReLU(−ON), subtracts the old flag in full, whatever its sign. So the flag is rebuilt from scratch at every step and cannot hold itself up in a loop. Reading the neighbour's flag back as a clean 0 or 1 matters too. Passing the raw value on lets noise walk the flag down along the path, because the clamp at 1 cuts the upward half of the noise and keeps the downward half: without the clean read, the flag faded to 0.3 over 90 cells at σ = 0.02.

Why 20 and not 1

One cell of distance could be worth 1. It is worth 20 because of noise. The runtime adds a little random noise to every register at every step, and each cell copies its neighbour's already noisy value, so errors pile up along the flood. The error in the difference between two neighbouring cells grows like σ√(2d) at a distance d from the goal. The path test has to tell "one step apart" from "not one step apart" through that error, and a larger step leaves more room. The other constants follow from that choice.

ConstantValueWhy
STEP20what one corridor step is worth, large enough that a step stays readable through accumulated noise
BIG25,000D at the goal. BIG / STEP = 1,250 cells is the longest path the field can measure
TOL6the window of the "exactly one step nearer" test; it must stay below STEP / 2 = 10
K26,000keeps the intermediates of the maximum positive
MUTE, MPIN120,000switch the flood off at the goal and the pin off everywhere else
ON_LO, ON_HI0.4, 0.6the band in which a neighbour's flag is read back as a clean 0 or 1

5.All 115 weights

Because every unit was written for a reason, the whole network fits on one screen. Figure 7 shows every tensor at full size. Hover a square for what that weight does, or click a unit to follow it from its inputs to its outputs.

Figure 7. The weight explorer. W1 is the 3 × 3 convolution, drawn as 27 rows (nine neighbourhood positions × three channels) by 32 units. W2 is 32 × 16 and W3 is 16 × 2, with the bias rows beside them. Colour shows sign and size. The corner rows of W1 are empty because no unit reads a diagonal neighbour: the maze is four-connected. Filter by program part, or click a square or a unit label to list one unit's incoming and outgoing weights.
Figure 8. How empty the network is. Left: non-zero against all numbers in each of the six tensors, on a log scale. W1 has 42 non-zero entries of 864, W2 36 of 512, W3 12 of 32, and the three bias vectors 24, 1 and 0. Right: the 115 split by program part. Checking a neighbour's flag and step, four times over, is the largest part (66). The flood itself takes 23. Only 19 distinct values occur.

The sparsity is not a curiosity. A dense pass through this network costs 1,408 multiply-adds per cell. Skipping the zeros, it costs 90. The page's own engine runs on the non-zero weights only, and we checked it against the full tensors.

6.Is it right, and how long does it take?

We ran the automaton on 128 mazes in five sizes from 17 × 17 to 49 × 49: 40 perfect mazes (exactly one route between any two cells), 40 braided mazes (with loops, so several routes compete), 40 mazes of rooms joined by doors, five serpentines that fold the whole grid into one corridor, and three mazes whose goal is walled off. A breadth-first search outside the automaton gave the reference answer. In all 128, the distance at every reachable cell, the set of cells on the path and the length read off the start cell were exact. The longest path was 1,150 cells. At no step of any run did a cell hold a distance before breadth-first search would have reached it: the wave is never ahead of the front, and it never lags. When the goal is walled off, only the start stays on.

Figure 9. Checked against breadth-first search. The tiles give the totals: 128 of 128 mazes exact, no cell ever ahead of the breadth-first front, longest path 1,150 cells. The grid breaks the test set down by kind and size. Hover a box to see every maze in it, with its path length and the steps it took.

The timing is just as exact. For 125 of these mazes (the sealed ones have no path), the flood reached the start at step L + 1, the path was complete at step 2L + 1, and every distance in the maze was exact one step after the flood reached the farthest cell. Fitting a line to each gives slopes of exactly 1 and 2 and intercepts of exactly 1, with no maze off the line. The automaton is never early, because a value moves at most one cell per step, and never late, because every cell updates at every step.

Figure 10. Settling time is a straight line. Steps to settle against path length for 125 mazes from 17 × 17 to 49 × 49. Switch between path complete (t = 2L + 1), wave reaches the start (t = L + 1) and every distance exact (t = farthest cell + 1). The fitted line and its largest deviation are shown; hover a dot for the maze.

Longer mazes simply take more steps. Trained recurrent networks can learn to extrapolate to larger mazes by running longer, but some degrade when run far past the point where they should stop. This automaton has a fixed point instead: once the answer is right, further steps change nothing. In a 292-cell maze the path was complete at step 585 and nothing on the path changed afterwards.

7.Noise, lazy cells and a changing maze

The runtime adds Gaussian noise of standard deviation σ to every register update at every step. This is where the design of section 4 pays off. We ran eight 33 × 33 mazes (six perfect, two braided) at ten noise levels. Up to σ = 0.05 all eight were solved exactly, with the largest error on a single step of the path at 4.3 against the 6 the test allows. At σ = 0.07, six of the eight were solved. At σ = 0.1 the error passes the tolerance and all eight lose part of the path. The error grows with the distance from the goal as predicted: like σ√d for a cell's value and like σ√(2d) for the difference between neighbours.

Figure 11. How much noise the program tolerates. Left: the worst single-step error of D along the path and the drift of D from its exact value, against σ, with the tolerance TOL = 6 shaded, and the number of the eight mazes still solved at each σ. Right: on a 510-cell serpentine at σ = 0.05, the measured standard deviation of the error against the distance from the goal, with the predicted σ√d (a cell's value) and σ√(2d) (two neighbours' difference).

The cells do not need a common clock either. If each cell updates only with some probability at each step, the answer is the same and arrives later. With every cell updating, the eight mazes took a median of 615 steps. With 80%, 50% and 30% of cells updating per step, they took 768.5, 1,239.5 and 2,071.5, and all eight were exact every time.

Figure 12. Lazy cells. Median steps to the exact path when only a share of the cells update at each step (100, 80, 50 and 30%). All eight mazes come out exact at every share.

Finally, we changed a settled maze and let the automaton carry on from the registers it already held. We opened a wall to make a shortcut (12 edits) or blocked a cell on the path to force a detour (8 edits). All 20 of 20 settled on the new exact answer. After a shortcut, the new path was right after a median of 98 steps, about the same as starting from empty registers (101). After a block, it took 155.5 steps, faster than starting again (215). Old distances that lose their support fall away by one step per step, and the path flag is rebuilt from scratch every step, so nothing stale can survive.

One edit is slow: moving the goal. The old goal's peak then has to drain away at one step per step. In our test, the path was right after 527 steps with the registers kept against 141 with them cleared, which is why the page clears the registers on every edit unless you switch that off.

Figure 13. Self-repair. Left: the number of cells with a wrong path flag or a wrong distance at each step after opening a wall (a shortcut) or closing a path cell (a detour), with the registers kept. Right: steps to the exact path with the registers kept against cleared, for all 20 edits. The tiles give the medians and the goal-moved case. All mazes are braided 33 × 33.

8.What it costs

Exactness has a price, and it is worth stating plainly. A breadth-first search on an ordinary computer visits each reachable cell once. The automaton recomputes every corridor cell at every step until the path is right. Counting cell updates, it does a median of 77.5 times more work than two breadth-first searches (one from the goal, one from the start), and between 1.5 and 1,150.5 times more across the 125 mazes. The runtime in the browser computes every grid cell, walls included, so it does more still. As a sequential algorithm, this is a poor one.

The comparison changes if the cells are hardware. In a regular array of identical cells that talk only to neighbours and compute in lockstep[22], all cells work at once, and the time is 2L + 1 parallel steps with a fixed, small amount of memory per cell and no queue. And the work that actually matters is no more than breadth-first search's: in the maze of Figure 14, the cells whose value changes at each step are exactly the breadth-first frontier at that step, at every step. From step 586 on, nothing changes at all.

Figure 14. Computed, changed and needed. For a 33 × 33 maze with a 292-cell path and 511 corridor cells: the cells computed at each step (all corridor cells), the cells whose registers change, and the breadth-first frontier, on a log scale. The middle and last curves coincide. Hover for values. The tiles compare cell updates with breadth-first search (median ×78 over 125 mazes), parallel steps (2L + 1) and the cost of one cell update, 90 multiply-adds skipping zeros against 1,408 dense.

There is also a hard limit on reach. With BIG = 25,000 and STEP = 20, the field can count 1,250 steps before it reaches zero. A 49 × 49 serpentine with a 1,150-cell path is solved exactly. A 57 × 57 serpentine with a 1,566-cell path is not: the flood dies out before it reaches the start, and only the start cell stays on. The limit can be moved by changing BIG, at the cost of larger numbers in 32-bit floats.

The algorithm is old. Shortest paths by classic, non-neural cellular automata go back at least to the 1990s[23,24], neural lattices with fixed local connections have spread waves from a goal to plan robot paths[25], and even a chemical medium can find the shortest route through a labyrinth by wave propagation[26]. We claim nothing new about the algorithm. What is new is where it lives and how it got there.

The closest neural cellular automaton. Earle and colleagues[13] constructed neural cellular automata for breadth-first and depth-first search, setting their weights analytically. Their breadth-first automaton floods from both the source and the target and already extracts all shortest paths at once, so marking every shortest path is not what sets this work apart. They also trained neural cellular automata on 16 × 16 mazes and tested them on 32 × 32. The differences here are four. An AI agent programmed the weights directly in weight space. The network graph is an existing, standard neural-cellular-automaton graph, not one designed for the task. The program needs 115 non-zero weights. And it was designed to tolerate noise at every step, which they do not report for their constructed models.

The closest agent-written network. Looped Weight-Space Programming[14], published while this work was being written up, also has an AI agent write the weights of a maze solver, and its algorithm is closely related: a wave of distances spreading one cell per loop from the goal, per-cell pointers, and a trace from the start back to the goal. They report that gradient descent on the same architecture solved 0% in every run they tried, and they are careful to add that this shows only that training did not find the weights under the settings tested. Under the hood, looped transformer is a neural cellular automaton: one token per cell, one shared block looped over every cell, and four attention heads that each put almost all their weight on a single neighbour, by giving it a score 100 higher than any other cell. A grid of identical cells updating from their four neighbours, again and again, is what a cellular automaton is. The two works therefore do the same thing in different notation, and the differences are in the notation and the size. Here the neighbour reads are a 3 × 3 convolution, with no attention and no tokens. It uses 115 non-zero weights against their 19,936, 173 times fewer, and 8 times fewer than the 928 of their smallest capped version. It marks all shortest paths rather than one, and it is built to survive per-step noise and live edits. Both solve Maze-Hard: their transformer and our Maze-Hard edition, which adds their per-cell pointer with the same order, down, left, right, up, each solve all 1,000 test mazes, ours with 208 non-zero weights, 96 times fewer than 19,936 and 4.5 times fewer than 928 (section 3).

Trained solvers. Spitznagel and Keuper report that a trained neural cellular automaton with a plain 3 × 3 convolution, about 50k parameters, run for a 100-step budget at inference, formed a valid path on only 2.54% of Maze-Hard's 30 × 30 mazes and an optimal one on 0.08%[27]. Maze-Hard keeps only mazes whose shortest path is longer than 110[15], and a 3 × 3 rule moves information at most one cell per step, so 100 steps cannot complete most of these paths whatever the weights are. Their result therefore does not separate training from the step budget. The narrow statement is this: a trained 3 × 3 automaton with a 100-step budget almost never completes a path, while a programmed 3 × 3 automaton given enough steps does, exactly. The trained recurrent reasoners on Maze-Hard use 27M[15], 7M[17] and 1.8M parameters[16,18], between about 15,000 and 235,000 times the 115 here (see the size comparison under the introduction). On Maze-Hard they reach 82.2% to 99.8%, as compiled in[14], and the Maze-Hard edition here reaches 100% (section 3). The settings differ: they learn from 1,000 training mazes given as token sequences, while the automaton is written, reads the grid as a picture, and took only its tie-break order from the data.

Extrapolation and overthinking. Recurrent "Deep Thinking" networks trained on small mazes solve larger ones by running for more iterations[28], and later work addressed their tendency to degrade when run far longer than needed[29]. Here both properties hold by construction: more steps reach longer paths, up to 1,250 cells, and the answer is a fixed point that extra steps leave alone. Value iteration networks[30], recurrent convolution with a maximum, are the nearest trained architecture to the max-of-four rule used here.

Conclusion

A maze solver in 115 numbers.An AI agent wrote a complete shortest-path solver into the weights of an unchanged neural-cellular-automaton graph, with no training, no data and no gradient. Every non-zero weight belongs to one of five named parts.
173 times smaller than the looped transformer.The agent-written looped transformer for mazes[14] uses 19,936 weights, and 928 at its smallest. Trained maze reasoners use 1.8M to 27M. Their network is essentially a neural cellular automaton written with attention, and this one solves the same kind of problem with 115 non-zero weights.
Maze-Hard, 1,000 of 1,000.On the benchmark's 1,000 test mazes the automaton lights every shortest path exactly. With a pointer register for the benchmark's one marked path, 208 non-zero weights, every answer is an exact match, with or without noise at every step. Trained reasoners of 1.8M to 27M parameters reach 82.2% to 99.8%.
Exact, and exactly on time.On 128 mazes up to 49 × 49 the distance field, the path and the length match breadth-first search in every case, and the path is complete at step 2L + 1 with no exception.
Built for a noisy, unsynchronised world.The constants were chosen against the runtime's noise: all eight test mazes are solved up to σ = 0.05, with 100, 80, 50 or 30% of the cells updating per step, and 20 of 20 edits repair themselves.
Honest about cost.As a sequential algorithm it does a median of 77.5 times the work of breadth-first search. The cells that actually change, though, are exactly the breadth-first frontier, and on parallel cells the time is 2L + 1 steps.

A network this small, whose every unit has a stated meaning, is also a natural test bed for interpretability methods, in the spirit of compiled models with known circuits[6,31]. Any method that claims to recover how a network solves a maze can be checked here against the program that was actually written.

Limits

Paths longer than 1,250 cells cannot be measured: the flood runs out and the path stops short. The maze is four-connected only, so a corridor that steps diagonally is not connected. Moving the goal without clearing the registers is slow, because the old peak drains one step per step. The answer costs far more cell updates than breadth-first search on a sequential machine. The model needs 32-bit floats, and 16-bit runtimes, iOS Safari and touch input were not tested. Noise robustness was measured on eight 33 × 33 mazes, and the edits on braided 33 × 33 mazes only. The Maze-Hard edition's tie-break order, down, left, right, up, was read off the dataset's answers, and Maze-Hard was run in NumPy and in this page's engine, not in a tokenised format. And because no network was trained on this task with the same graph, nothing here compares written weights with learned ones on accuracy, robustness or speed.

What's next

The obvious next test is the same graph trained by gradient descent on Maze-Hard's training mazes, including training that starts from the written weights to see whether it keeps them. Beyond mazes, the flood-and-pointer pattern carries over to any grid task where information has to travel: graph search on general graphs, or several goals at once, where the automaton already flows to the nearer one.

Citation

If you use this work, please cite it as follows.

@misc{moaddel2026maze,
  title  = {{Cellular Weight-Space Programming: 115 Numbers Find Every Shortest Path in Any Maze}},
  author = {Moaddel, Arash and Moaddel, Ashkan and Uller, Nina},
  year   = {2026},
  month  = nov,
  note   = {Article, ibiLAB, Copenhagen},
  url    = {https://comp-minds-research.onrender.com/maze/maze.html}
}

References

  1. Takehi, R., Teoh, J., Zhang, A. & Khattab, O. Sparks of weight-space programming: LLMs can natively read & write neural network weights. Blog post, MIT CSAIL, 2 November 2026. rikiyat.github.io/blog/weight-space-programming
  2. Singh, C. Weight-space programming from scratch on simple tasks. Web report, 2 November 2026. csinva.io
  3. McCulloch, W. S. & Pitts, W. A logical calculus of the ideas immanent in nervous activity. Bull. Math. Biophys. 5, 115–133 (1943). doi:10.1007/BF02478259
  4. Siegelmann, H. T. & Sontag, E. D. On the computational power of neural nets. J. Comput. Syst. Sci. 50, 132–150 (1995). doi:10.1006/jcss.1995.1013
  5. Weiss, G., Goldberg, Y. & Yahav, E. Thinking like transformers. Preprint at arXiv:2106.06981 (2021).
  6. Lindner, D. et al. Tracr: compiled transformers as a laboratory for interpretability. Preprint at arXiv:2301.05062 (2023).
  7. Giannou, A., Rajput, S., Sohn, J., Lee, K., Lee, J. D. & Papailiopoulos, D. Looped transformers as programmable computers. Preprint at arXiv:2301.13196 (2023).
  8. Back de Luca, A. & Fountoulakis, K. Simulation of graph algorithms with looped transformers. Preprint at arXiv:2402.01107 (2024).
  9. Gilpin, W. Cellular automata as convolutional neural networks. Phys. Rev. E 100, 032402 (2019). doi:10.1103/PhysRevE.100.032402
  10. Mordvintsev, A., Randazzo, E., Niklasson, E. & Levin, M. Growing neural cellular automata. Distill 5, e23 (2020). doi:10.23915/distill.00023
  11. Moore, E. F. The shortest path through a maze. In Proc. Int. Symp. on the Theory of Switching, Part II (Annals of the Computation Laboratory of Harvard University 30), 285–292 (Harvard Univ. Press, 1959).
  12. Lee, C. Y. An algorithm for path connections and its applications. IRE Trans. Electron. Comput. EC-10, 346–365 (1961). doi:10.1109/TEC.1961.5219222
  13. Earle, S., Yildiz, O., Togelius, J. & Hegde, C. Pathfinding neural cellular automata. Preprint at arXiv:2301.06820 (2023).
  14. Elsayed, A., Heakl, A., Shaker, A., Khan, F., Khan, S. & Claude Opus 5.5. Looped weight-space programming: LLM-written transformers for long algorithmic reasoning. Blog post, MBZUAI, 23 November 2026. mbzuai-oryx.github.io/LoopedWSP
  15. Wang, G. et al. Hierarchical reasoning model. Preprint at arXiv:2506.21734 (2025).
  16. Chen, W. X., Gladstone, A., Li, Z. M., Ji, H. & Du, Y. Energy-based reasoners: your recurrent reasoner should be an energy-based model. Preprint at arXiv:2611.08977 (2026).
  17. Jolicoeur-Martineau, A. Less is more: recursive reasoning with tiny networks. Preprint at arXiv:2510.04871 (2025).
  18. Davis, L., Haller, L., Alfarano, A. & Santolucito, M. Lattice deduction transformers. Preprint at arXiv:2605.08605 (2026).
  19. Bellman, R. On a routing problem. Q. Appl. Math. 16, 87–90 (1958). doi:10.1090/qam/102435
  20. Rosenfeld, A. & Pfaltz, J. L. Sequential operations in digital picture processing. J. ACM 13, 471–494 (1966). doi:10.1145/321356.321357
  21. Rosenfeld, A. & Pfaltz, J. L. Distance functions on digital pictures. Pattern Recognit. 1, 33–61 (1968). doi:10.1016/0031-3203(68)90013-7
  22. Kung, H. T. Why systolic architectures? Computer 15(1), 37–46 (1982). doi:10.1109/MC.1982.1653825
  23. Adamatzky, A. Computation of shortest path in cellular automata. Math. Comput. Model. 23, 105–113 (1996). doi:10.1016/0895-7177(96)00006-4
  24. Tsompanas, M.-A. I., Dourvas, N. I., Ioannidis, K., Sirakoulis, G. Ch., Hoffmann, R. & Adamatzky, A. Cellular automata applications in shortest path problem. Preprint at arXiv:1712.05202 (2017); chapter in Adamatzky, A. (ed.) Shortest Path Solvers: From Software to Wetware (Springer, 2018).
  25. Glasius, R., Komoda, A. & Gielen, S. C. A. M. Neural network dynamics for path planning and obstacle avoidance. Neural Netw. 8, 125–133 (1995). doi:10.1016/0893-6080(94)E0045-M
  26. Steinbock, O., Tóth, Á. & Showalter, K. Navigating complex labyrinths: optimal paths from chemical waves. Science 267, 868–871 (1995). doi:10.1126/science.267.5199.868
  27. Spitznagel, M. & Keuper, J. 2D spatial reasoning with adaptive neural cellular automata. Preprint at arXiv:2610.08518 (2026).
  28. Schwarzschild, A. et al. Can you learn an algorithm? Generalizing from easy to hard problems with recurrent networks. Preprint at arXiv:2106.04537 (2021).
  29. Bansal, A. et al. End-to-end algorithm synthesis with recurrent networks: logical extrapolation without overthinking. Preprint at arXiv:2202.05826 (2022).
  30. Tamar, A., Wu, Y., Thomas, G., Levine, S. & Abbeel, P. Value iteration networks. In Advances in Neural Information Processing Systems 29, 2154–2162 (2016). Preprint at arXiv:1602.02867.
  31. Gupta, R., Arcuschin, I., Kwa, T. & Garriga-Alonso, A. InterpBench: semi-synthetic transformers for evaluating mechanistic interpretability techniques. Preprint at arXiv:2407.14494 (2024).
  32. Sapient Inc. maze-30x30-hard-1k: the Maze-Hard benchmark of [15], 1,000 training and 1,000 test mazes. Dataset, Hugging Face (2025). huggingface.co/datasets/sapientinc/maze-30x30-hard-1k