The state of the art in error correction — sparse graphs, belief propagation, and iterative decoding. The code behind 5G, modern WiFi, and satellite TV.
LDPC codes are linear block codes with a sparse parity-check matrix (most entries are 0). This sparsity enables a powerful decoding algorithm: iterative message passing on a bipartite graph called a Tanner graph.
Unlike Hamming codes (which decode in one step via syndrome lookup), LDPC decodes iteratively — variable nodes and check nodes exchange messages until they converge on a valid codeword. This makes LDPC codes approach the Shannon limit (the theoretical maximum channel capacity).
LDPC codes were invented by Robert Gallager in his 1963 MIT PhD thesis, but were forgotten for 30 years because computers weren't powerful enough to decode them. Rediscovered in the 1990s, they now power most modern digital communication.
Our puzzle uses a small (10,5) regular LDPC code: 5 data bits + 5 parity bits. Each check node connects to 4 variable nodes; each variable node connects to 2 check nodes.
H matrix (5 checks × 10 variables):
1 1 0 1 0 1 0 0 0 0 # check 0: v0⊕v1⊕v3⊕v5 = 0
0 1 1 0 1 0 1 0 0 0 # check 1: v1⊕v2⊕v4⊕v6 = 0
0 0 1 1 0 1 0 1 0 0 # check 2: v2⊕v3⊕v5⊕v7 = 0
0 0 0 0 1 0 1 1 1 0 # check 3: v4⊕v6⊕v7⊕v8 = 0
1 0 0 0 0 0 0 1 0 1 # check 4: v0⊕v7⊕v9 = 0
The Tanner graph has variable nodes (v0-v9, circles) connected to check nodes (c0-c4, squares) where H has a 1. Decoding:
def ldpc_decode(noisy, H, max_iters=50):
n = len(noisy)
m = len(H)
for _ in range(max_iters):
# Compute check node values
checks = []
for r in range(m):
val = 0
for c in range(n):
if H[r][c]:
val ^= noisy[c]
checks.append(val == 0) # True if satisfied
if all(checks):
break # converged
# Flip variable nodes with > threshold violated checks
threshold = 1 # flip if > 1 violated check connected
for c in range(n):
violated = 0
total = 0
for r in range(m):
if H[r][c]:
total += 1
if not checks[r]:
violated += 1
if violated > total // 2:
noisy[c] ^= 1
return noisy[:k] # first k bits = data
| Level | What Happens | Time Estimate |
|---|---|---|
| 1 | Clean signal, no errors | <10s |
| 2-3 | 1-3 bit flips per block | 20-60s |
| 4-5 | 10-20% of bits flipped | 1-2m |
| 6-7 | 20-30% bit flips, may require multiple iterations | 2-5m |