Prolog's pattern matching makes this elegant. The constraint-based approach for state space pruning is clever.