Sprague-Grundy — Grundy Numbers via mex, and the XOR Sum Rule

grundy(p) = mex of children's Grundy values. 0 means the mover loses. A sum of games is decided by the XOR of component Grundy values.

step 0

Position DAG — bottom-up Grundy labeling

Press Step to begin computing Grundy numbers from the terminal positions upward.
node being computed already labeled chosen mex

Sum of games — XOR rule

Pick a few positions; the disjunctive sum's Grundy is their XOR.
A single game is a loss for the mover when its Grundy value is 0. A sum is a loss when the XOR of components is 0.
grundy(terminal) = mex{} = 0. Each non-terminal takes the mex of its children's Grundy values. Watch the labels fill in.
Self-contained visualization. Impartial, normal-play games (last to move wins). The mex of a set is its smallest missing non-negative integer. See junior.md for the definitions and professional.md for the proof that grundy(sum) = XOR of component Grundy values.