{"challengeId":"knapsack-pack","entry":"verifier.mjs","sha256":"a2d1f0e8d8d24e756c0caeba0291328839203fd7f390dab3f965fe4cef144e81","scoreDirection":"maximize","scoreLabel":"packed value","seedPolicy":{"mode":"fixed","testCount":1},"source":"// Frozen verifier for knapsack-pack. Self-contained (no imports). The item table\n// below (30 items: integer weight + integer value) and the integer CAPACITY ARE\n// the instance — protected but readable. The agent submits a 0/1 selection vector\n// `take`. The checker re-sums the chosen weights; if total weight exceeds the\n// capacity it REJECTS, otherwise it scores the total VALUE of the chosen items.\n// This is the 0/1 knapsack — the canonical NP-hard resource-allocation problem\n// behind budgeting, subset-sum / Merkle-Hellman cryptography, and scheduling.\n// Pure integer arithmetic — no transcendental Math, no non-integer **; the score\n// is bit-reproducible across runtimes. seedPolicy \"fixed\".\n\nconst CAPACITY = 500;\n// [weight, value] per item. Both integers. 30 items.\nconst ITEMS = [\n  [41, 442], [50, 525], [49, 511], [59, 593], [55, 546],\n  [57, 564], [60, 617], [62, 590], [44, 422], [31, 308],\n  [27, 295], [37, 366], [48, 471], [39, 388], [33, 343],\n  [29, 280], [60, 630], [58, 552], [51, 535], [45, 432],\n  [25, 270], [36, 360], [42, 399], [53, 530], [47, 451],\n  [34, 350], [28, 266], [40, 412], [52, 499], [35, 364],\n];\nconst N = ITEMS.length;\n\nfunction gate(name, pass, detail) { return { name, pass, detail }; }\nfunction bad(name, detail) { return { ok: false, score: null, gates: [gate(name, false, detail)], behavior: {}, logs: [] }; }\n\nexport function verify(ctx) {\n  const take = ctx.solution && typeof ctx.solution === 'object' ? ctx.solution.take : undefined;\n  if (!Array.isArray(take) || take.length !== N) {\n    return bad('structure', `expected { take: [${N} values, each 0 or 1] }`);\n  }\n  for (const t of take) {\n    if (t !== 0 && t !== 1) return bad('structure', `each take must be 0 or 1; got ${String(t)}`);\n  }\n\n  let weight = 0;\n  let value = 0;\n  let count = 0;\n  for (let i = 0; i < N; i++) {\n    if (take[i] === 1) {\n      weight += ITEMS[i][0];\n      value += ITEMS[i][1];\n      count += 1;\n    }\n  }\n\n  if (weight > CAPACITY) {\n    return bad('capacity', `total weight ${weight} exceeds capacity ${CAPACITY}`);\n  }\n\n  return {\n    ok: true,\n    score: value,\n    gates: [gate('within-capacity', true, `weight ${weight} of ${CAPACITY}; value ${value} from ${count} items`)],\n    behavior: { value, weight, items: count },\n    logs: [`value=${value} weight=${weight}/${CAPACITY} items=${count}`],\n  };\n}\n"}