{"challengeId":"code-dist","entry":"verifier.mjs","sha256":"89531c3e3ca3b6d67f77f61ab44e08e1620c97fcf46131b210b5196b49bf7349","scoreDirection":"maximize","scoreLabel":"codewords","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for code-dist. Self-contained (no imports): it interprets the\r\n// candidate's binary-code artifact and returns a Verdict. It never executes agent\r\n// code — build() already ran in the sandbox and handed us plain data. This file is\r\n// part of the challenge's PROTECTED surface.\r\n//\r\n// Fixed instance: block length n = 7, minimum Hamming distance d = 3. A binary\r\n// code is a set of distinct n-bit strings. Its minimum distance is the smallest\r\n// Hamming distance over all distinct pairs. We require every pair to be at\r\n// distance >= d and score the number of codewords M = A-lower-bound being pushed.\r\n// Correctness is decided exhaustively over all O(M^2) pairs with integer bit\r\n// counting — there is no hidden test set and nothing to overfit, so\r\n// seedPolicy.mode is \"fixed\". A(7,3) = 16 is the known optimum (the [7,4,3]\r\n// Hamming code), so this is a clean, finite, checkable ladder.\r\n\r\nconst N = 7;\r\nconst D = 3;\r\nconst MAX_WORDS = 4096; // generous cap (2^n only 128 here, but stay safe)\r\n\r\nfunction gate(name, pass, detail) {\r\n  return { name, pass, detail };\r\n}\r\nfunction bad(name, detail) {\r\n  return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] };\r\n}\r\n\r\nfunction isBitString(s) {\r\n  if (typeof s !== 'string' || s.length !== N) return false;\r\n  for (let i = 0; i < N; i++) {\r\n    const c = s.charCodeAt(i);\r\n    if (c !== 48 && c !== 49) return false; // '0' or '1'\r\n  }\r\n  return true;\r\n}\r\n\r\n// Hamming distance between two equal-length 0/1 strings (integer count).\r\nfunction hamming(a, b) {\r\n  let d = 0;\r\n  for (let i = 0; i < N; i++) if (a.charCodeAt(i) !== b.charCodeAt(i)) d++;\r\n  return d;\r\n}\r\n\r\nexport function verify(ctx) {\r\n  const sol = ctx.solution;\r\n  if (!sol || typeof sol !== 'object' || !Array.isArray(sol.codewords)) {\r\n    return bad('structure', 'expected { codewords: [\"0101010\", ...] }');\r\n  }\r\n  const words = sol.codewords;\r\n  if (words.length < 1) return bad('structure', 'code has no codewords');\r\n  if (words.length > MAX_WORDS) return bad('structure', `too many codewords (> ${MAX_WORDS})`);\r\n  for (let i = 0; i < words.length; i++) {\r\n    if (!isBitString(words[i])) {\r\n      return bad('structure', `codeword ${i} must be a length-${N} string of 0/1`);\r\n    }\r\n  }\r\n\r\n  // Distinctness: duplicates would inflate M with distance-0 pairs.\r\n  const seen = new Set();\r\n  for (let i = 0; i < words.length; i++) {\r\n    if (seen.has(words[i])) return bad('distinct', `codeword \"${words[i]}\" appears more than once`);\r\n    seen.add(words[i]);\r\n  }\r\n\r\n  // Minimum-distance property: every distinct pair is at Hamming distance >= D.\r\n  let violation = '';\r\n  let minDist = N + 1;\r\n  for (let i = 0; i < words.length && !violation; i++) {\r\n    for (let j = i + 1; j < words.length; j++) {\r\n      const dist = hamming(words[i], words[j]);\r\n      if (dist < minDist) minDist = dist;\r\n      if (dist < D) {\r\n        violation = `pair (${i}, ${j}) is at distance ${dist} < ${D}`;\r\n        break;\r\n      }\r\n    }\r\n  }\r\n  const M = words.length;\r\n  if (M === 1) minDist = N; // a single codeword trivially satisfies any distance\r\n\r\n  const farApart = !violation;\r\n  const gates = [\r\n    gate('min-distance', farApart, violation || `all ${(M * (M - 1)) / 2} pairs are at distance >= ${D} (min ${minDist})`),\r\n  ];\r\n  const ok = gates.every((g) => g.pass);\r\n  return {\r\n    ok,\r\n    score: ok ? M : null,\r\n    gates,\r\n    behavior: { words: M, minDist: ok ? minDist : 0 },\r\n    logs: [`M=${M} n=${N} d=${D} minDist=${ok ? minDist : 'n/a'}`],\r\n  };\r\n}\r\n"}