Grundy Numbers Calculator
Free online grundy numbers calculator. Enter your values and get instant results with the formula, step-by-step working, a worked example and FAQs — everything runs locally in your browser on Calcton, no signup required.
中文版:Grundy 数在线计算器
原理:Sprague–Grundy 定理是组合博弈论的基石。对「从一堆 n 颗石子中每次取走 S 中某个数量」的减法博弈,定义 Grundy 数 sg(n) = mex{sg(n−s) : s ∈ S}(mex 为不在集合内的最小非负整数)。sg(n) = 0 当且仅当先手必败;对多堆博弈,整局异或 sg(n₁) ⊕ sg(n₂) ⊕ … = 0 当且仅当先手必败——这就是 Nim 定理。集合 {1, 2, 3} 给出 sg(n) = n mod 4;集合 {1, 3, 4} 给出序列 0,1,0,1,2,3,2 以 7 为周期循环。
步骤:输入可取走的石子数集合与计算范围 N,得到 Grundy 序列、必败态位置与周期检测结果。
示例:S = {1, 3, 4} 时前 13 项为 0, 1, 0, 1, 2, 3, 2, 0, 1, 0, 1, 2, 3,周期 = 7,必败态为 0, 7, 14, 21, 28;三堆各 1、1、3 颗时 1 ⊕ 1 ⊕ 3 = 3 ≠ 0,先手必胜。
注意事项:集合元素须为正整数且不超过 N;周期检测只在前 N 项内寻找(周期 ≤ 40),部分集合存在预热段(前几项不进入周期),此时报告未检出。多堆判定直接对各堆 sg 值取异或即可,无需展开搜索。
相关:{1, 3, 4} 周期 7;3 为演示异或值;必败态间隔 7。
How to use the Grundy Numbers Calculator
- Fill in the inputs with your own numbers — every field shows what it expects.
- The result updates instantly as you type; no "Calculate" click needed.
- Read the result card for the main figure, the step-by-step formula, and practical notes.
Frequently asked questions
Is the Grundy Numbers Calculator free?
Yes — all math calculators on Calcton are free, with no sign-up required. Your inputs are processed in your browser and never sent to a server.
Is there a Chinese version of this tool?
Yes. Use the Chinese version link above — it is the same calculator with the interface in Simplified Chinese.
References
Formulas and benchmarks used by this calculator follow these published sources.
KevinContent LeadCalcton Editorial Team · Last updated 2026-10-01
Kevin maintains Calcton's formula verification and content: every calculator cites the standard it implements, worked examples are recomputed programmatically, and health benchmarks follow WHO and international guidelines.
Related calculators
More in this category: Math calculators
About math calculators
Free online math calculators for algebra, statistics, number theory and everyday arithmetic — from quadratic equations and matrices to percentages, fractions and prime factorization, each with step-by-step formulas.