{"challengeId":"busy-beaver","entry":"verifier.mjs","sha256":"483be6d9f6c5de1e09bea225d7ec44912c275c3d334ab310b2f043cff1fd4184","scoreDirection":"maximize","scoreLabel":"steps","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for busy-beaver. Self-contained (no imports): it interprets the\n// candidate's Turing-machine artifact and SIMULATES it deterministically. It never\n// executes agent code — build() already ran in the sandbox and handed us a plain\n// machine description. This file is part of the challenge's PROTECTED surface.\n//\n// Model: a 2-symbol (0/1), n-state Turing machine on a two-way-infinite tape that\n// starts all-blank (0). Transitions are total over (state, symbol). The machine\n// runs from state 0 at position 0 until it enters the HALT state. The Busy Beaver\n// function S(n) is the maximum number of steps any halting n-state machine takes.\n//\n// Because we cannot decide halting in general, the verifier imposes a STEP_CAP and\n// accepts only machines that halt within it — so the score is always a PROVEN,\n// fully-reproduced halting run. seedPolicy.mode is \"fixed\" (the blank tape is the\n// only input; there is nothing to overfit).\n\nconst MAX_STATES = 6;\nconst STEP_CAP = 2_000_000; // machines that run longer are not acceptable here\n\nfunction gate(name, pass, detail) {\n  return { name, pass, detail };\n}\nfunction bad(name, detail) {\n  return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] };\n}\n\nfunction isMove(x) {\n  return x === 'L' || x === 'R';\n}\n\nexport function verify(ctx) {\n  const sol = ctx.solution;\n  const machine = sol && typeof sol === 'object' ? sol.machine : undefined;\n  if (!machine || typeof machine !== 'object') {\n    return bad('structure', 'expected { machine: { n, transitions } }');\n  }\n  const n = machine.n;\n  if (!Number.isInteger(n) || n < 1 || n > MAX_STATES) {\n    return bad('structure', `n (state count) must be an integer in 1..${MAX_STATES}`);\n  }\n  const T = machine.transitions;\n  if (!Array.isArray(T) || T.length !== n) {\n    return bad('structure', `transitions must be an array of ${n} states`);\n  }\n  // Validate the full transition table: transitions[state][symbol] = [write, move, next]\n  for (let s = 0; s < n; s++) {\n    const row = T[s];\n    if (!Array.isArray(row) || row.length !== 2) {\n      return bad('structure', `state ${s} must list exactly 2 rules (for symbols 0 and 1)`);\n    }\n    for (let sym = 0; sym < 2; sym++) {\n      const rule = row[sym];\n      if (!Array.isArray(rule) || rule.length !== 3) {\n        return bad('structure', `rule for (state ${s}, symbol ${sym}) must be [write, move, next]`);\n      }\n      const [w, mv, nx] = rule;\n      if (w !== 0 && w !== 1) return bad('structure', `(state ${s}, symbol ${sym}) write must be 0 or 1`);\n      if (!isMove(mv)) return bad('structure', `(state ${s}, symbol ${sym}) move must be 'L' or 'R'`);\n      const nextOk = nx === 'H' || (Number.isInteger(nx) && nx >= 0 && nx < n);\n      if (!nextOk) return bad('structure', `(state ${s}, symbol ${sym}) next must be 0..${n - 1} or 'H'`);\n    }\n  }\n\n  // Deterministic simulation from a blank tape.\n  const tape = new Map(); // position -> 1 (absent = 0)\n  let pos = 0;\n  let state = 0;\n  let steps = 0;\n  let halted = false;\n  while (steps < STEP_CAP) {\n    const sym = tape.get(pos) === 1 ? 1 : 0;\n    const [w, mv, nx] = T[state][sym];\n    if (w === 1) tape.set(pos, 1);\n    else tape.delete(pos);\n    pos += mv === 'R' ? 1 : -1;\n    steps++;\n    if (nx === 'H') {\n      halted = true;\n      break;\n    }\n    state = nx;\n  }\n\n  if (!halted) {\n    return {\n      ok: false,\n      score: null,\n      gates: [gate('halts-within-cap', false, `did not halt within ${STEP_CAP.toLocaleString()} steps`)],\n      behavior: {},\n      logs: [`ran ${steps} steps without halting`],\n    };\n  }\n\n  let ones = 0;\n  for (const v of tape.values()) if (v === 1) ones++;\n\n  const gates = [gate('halts-within-cap', true, `halted after ${steps} steps`)];\n  return {\n    ok: true,\n    score: steps,\n    gates,\n    behavior: { states: n, ones },\n    logs: [`states=${n} steps=${steps} ones=${ones}`],\n  };\n}\n"}