Gerrymandle Teaches the One Skill Every Floor Plan Secretly Needs: Connected Regions
Play Gerrymandle, then rebuild it in NetworkX. A hands-on tutorial on contiguous-region partitioning — the skill behind districting and floor-plan zoning.
Signal. A new daily browser puzzle called Gerrymandle (gerrymandle.cc, posted to Show HN this week) hands you a grid of coloured houses and one job: click adjacent tiles into equal-size districts so your party wins more of them than anyone else. The rule that makes it hard is the same rule that makes it useful to us: each district must be one connected shape, no islands allowed. That single contiguity constraint is also the quiet villain in every floor-plate zoning exercise you have ever fought with.
←TODAY: In 2026, after a Supreme Court ruling demanding proof of discriminatory intent over effect, more than a quarter of US congressional seats have been redrawn mid-decade — line-drawing is now software. →3012: The same partition algorithms that carve voters carve zones, fire compartments, and energy clusters across a living Zurich. Fulcrum: A district and a room are the same object — a connected subgraph under a fairness constraint — and whoever owns the algorithm owns the outcome.
System. Gerrymandering runs on two moves, both purely topological. Packing crams opponents into a few landslide districts so their surplus votes evaporate; cracking smears the rest thin so they fall short everywhere. As The New York Times argued in its June 2026 opinion piece on parties redistricting “to the max,” the lines move while the vote totals barely do — North Carolina elected an even split in 2022, then sent 10 of 14 Republicans in 2024 on roughly the same numbers. The houses didn’t move. The graph partition did. For an architect this should feel uncomfortably familiar: it is exactly what happens when a program-area diagram gets “optimised” until the daylight all pools in the units that photograph well.
Street. Strip the politics and you are left with a clean computational-design problem — partition a grid into equal, contiguous regions that satisfy a per-region rule — and the cheapest way to learn it is the tool the game is secretly built on.
The Tool: NetworkX (maintained by the NetworkX developers, pure-Python, BSD-licensed) is the graph library that turns “is this district legal?” into one function call. It is worth a computational designer’s afternoon because adjacency — which tile, room, or riser touches which — is the data structure underneath districting, clash detection, and space planning alike. PAZ’s own Brick — Hack concept panel already leans on it: Turán’s 1944 brick-factory problem is the same library counting edge crossings for MEP coordination.
Setup:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install networkx matplotlib
python - <<'PY'
import networkx as nx
G = nx.grid_2d_graph(6, 6) # the Gerrymandle board, tiles as a 4-neighbour grid
print(G.number_of_nodes(), "tiles,", G.number_of_edges(), "adjacencies")
print("connected board:", nx.is_connected(G))
PY
First steps:
- Model the board. The
grid_2d_graph(6, 6)above is your map: every tile is a node, every shared edge an adjacency. This is the same move you make when you turn a plan into a room-adjacency graph. - Group a district. Pick a set of tiles —
district = {(0,0),(0,1),(1,1),(2,1)}— and takeG.subgraph(district). That subgraph is your candidate region. - Check the law. Run
nx.is_connected(...)on it.Truemeans one legal shape;Falsemeans you drew an island and the referee — or the building inspector — rejects it.
Atelier: In a Swiss studio this is not a metaphor. Swap voters for net floor area and districts for Brandabschnitte (fire compartments) or heating zones, and the contiguity check becomes a pre-flight validator: no compartment is allowed to be two disconnected blobs joined only by a corridor you forgot to draw. Run it on the room-adjacency graph before the Wettbewerb deadline, not after the Bauleitung finds it on site.
Hack: This Hack teaches you to prove a set of tiles forms one legal district — no islands — in five lines, the Geometry of grid contiguity. Same code, same answer, whether the tiles are precincts or rooms.
import networkx as nx
G = nx.grid_2d_graph(6, 6) # board tiles, 4-neighbour adjacency
district = {(0,0),(0,1),(1,1),(2,1)} # the tiles you grouped
ok = nx.is_connected(G.subgraph(district))
print("Legal district" if ok else "Island detected — illegal")
Move. Play one round of Gerrymandle by hand, lose, then rebuild the same board in NetworkX and let is_connected tell you which of your guesses were even legal. The point is not to become a better gerrymanderer — it is to feel, in your fingers, that a fairness rule and a building code are both just constraints on a partition. From the late 2070s I can tell you which version of this skill aged badly: the studios that let a black-box “optimiser” draw their zones and could not explain why a unit got the bad daylight. If you adopt a generative space-planning tool this quarter, demand it show its constraint graph. When the vendor disappears, a 25-year-old should still be able to open the partition and ask: is this connected, is this fair, and who decided?
Learn-it:
- Play it: gerrymandle.cc — one fresh districting puzzle a day.
- The library: networkx.org — docs, tutorial, and the
is_connected/subgraphreference. - The code: github.com/networkx/networkx — clone it, read the algorithms module.
- Root concept: Gerrymandering — packing, cracking, and the 1812 Gerry-mander.
- PAZ note: compare with PAZ’s Brick — Hack concept panel — same NetworkX, counting MEP clash crossings instead of districts.
SOURCE · ↗
PAZ Kaffi · multidisciplinary editorial, led by PAZ Academy