// Independent Busy Beaver simulator (written for this review; no code from bbchallenge). // Machine format: standard text, e.g. 1RB1LC_1RC1RB_1RD0LE_1LA1LD_1RZ0LA ("---" or a state outside A.. = halt). // Step count includes the halting step (paper, sections/TMs.tex: "includes the final halting step"). // sigma_write: nonzero cells if the halting transition's written symbol is applied (historical 1RZ convention); // sigma_nowrite: nonzero cells if halting writes nothing ("---" convention). function parse(s) { const rows = s.split("_"), n = rows.length, k = rows[0].length / 3; const T = []; for (let q = 0; q < n; q++) for (let a = 0; a < k; a++) { const t = rows[q].substr(3 * a, 3); const st = t[2].charCodeAt(0) - 65; if (t === "---" || st < 0 || st >= n) T.push({ halt: true, w: t === "---" ? null : +t[0], d: t[1] === "R" ? 1 : -1 }); else T.push({ halt: false, w: +t[0], d: t[1] === "R" ? 1 : -1, q: st }); } return { n, k, T }; } function run(s, limit = 1e9) { const { k, T } = parse(s); const SIZE = 1 << 20, tape = new Uint8Array(SIZE); let pos = SIZE >> 1, q = 0, steps = 0, lo = pos, hi = pos; for (;;) { const t = T[q * k + tape[pos]]; steps++; if (t.halt) { let ones = 0; for (let i = lo; i <= hi; i++) if (tape[i]) ones++; const wrote = t.w === null ? ones : ones - (tape[pos] ? 1 : 0) + (t.w ? 1 : 0); return { halted: true, steps, sigma_write: wrote, sigma_nowrite: ones }; } if (steps > limit) return { halted: false, steps }; tape[pos] = t.w; pos += t.d; q = t.q; if (pos < lo) lo = pos; if (pos > hi) hi = pos; if (pos <= 0 || pos >= SIZE - 1) throw new Error("tape overflow"); } } module.exports = { parse, run }; if (require.main === module) { // Winners listed in arXiv:2509.12337v2, Appendix "Busy Beaver winners and champions". const cases = [ ["S(2)=6, Sigma(2)=4", "1RB1LB_1LA1RZ", 6, 4], ["S(3)=21", "1RB1RZ_1LB0RC_1LC1LA", 21, null], ["Sigma(3)=6 #1", "1RB1RZ_0RC1RB_1LC1LA", null, 6], ["S(4)=107, Sigma(4)=13", "1RB1LB_1LA0LC_1RZ1LD_1RD0RA", 107, 13], ["Sigma(4)=13 #2", "1RB0RC_1LA1RA_1RZ1RD_1LD0LB", null, 13], ["S(5)=47,176,870, Sigma(5)=4,098", "1RB1LC_1RC1RB_1RD0LE_1LA1LD_1RZ0LA", 47176870, 4098], ["Sigma(5)=4,098 #2", "1RB1RA_1LC1LB_1RA1LD_1RA1LE_1RZ0LC", null, 4098], ["S(2,3)=38, Sigma(2,3)=9", "1RB2LB1RZ_2LA2RB1LB", 38, 9], ["S(2,4)=3,932,964, Sigma(2,4)=2,050", "1RB2LA1RA1RA_1LB1LA3RB1RZ", 3932964, 2050], ]; let ok = true; for (const [name, m, S, Sig] of cases) { const t0 = Date.now(), r = run(m); const pass = r.halted && (S === null || r.steps === S) && (Sig === null || r.sigma_write === Sig); ok = ok && pass; console.log((pass ? "PASS " : "FAIL ") + name.padEnd(36) + m.padEnd(38) + " steps=" + r.steps + " sigma(halt writes)=" + r.sigma_write + " sigma(halt no write)=" + r.sigma_nowrite + " " + (Date.now() - t0) + "ms"); } const syn = 21 ** 10; console.log("(4n+1)^(2n) for n=5:", syn.toLocaleString("en"), " / 181,385,789 =", (syn / 181385789).toFixed(1), " 133,005,895+48,379,894 =", (133005895 + 48379894).toLocaleString("en")); console.log(ok ? "ALL PASS" : "SOME FAIL"); }