The astonishing theorem of combinatorial game theory: every impartial game under normal play is equivalent to a single nim-heap. Its size is the position’s Grundy number — the mex (minimum excludant) of the Grundy numbers of the positions you can move to. A sum of games is won exactly like nim: XOR the Grundy numbers, non-zero means the mover wins. One theorem collapses a universe of games onto nim.
The demo computes the Grundy numbers of the subtraction game {1,2,3} and shows they are k mod 4: live demo
“Sprague-Grundy solves all two-player games.” — only impartial games (same moves for both) under normal play; partisan games need surreal numbers, misère play differs. cited
A whole game, weighed as one number. theorem
On i-13, mex(0,1,2)=3 and the subtraction-game Grundy values are periodic (k mod 4):