"algorithm": "The new algorithm constructs a large Salem\u2013Spencer set by iteratively adding numbers from 1 to n based on a scoring system that prioritizes numbers with fewer potential 3-term arithmetic progressions, utilizing a hash set for efficient membership checks and a numpy random number generator for deterministic randomness.",
"code": "import numpy as np\n\ndef heuristic(n, rng=None):\n if isinstance(rng, int):\n rng = np.random.default_rng(rng)\n elif rng is None:\n rng = np.random.default_rng()\n\n S = set()\n scores = np.zeros(n+1, dtype=int)\n for x in range(1, n+1):\n scores[x] = sum(1 for y in S if 2*x - y in S or 2*y - x in S or x + y in S)\n for _ in range(n):\n candidates = [x for x in range(1, n+1) if x not in S and scores[x] == 0]\n if not candidates:\n break\n x = min(candidates)\n S.add(x)\n for y in S:\n if 2*x - y > 0 and 2*x - y <= n:\n scores[2*x - y] += 1\n if 2*y - x > 0 and 2*y - x <= n:\n scores[2*y - x] += 1\n if x + y > 0 and x + y <= n and (x + y) % 2 == 0:\n scores[(x + y) // 2] += 1\n return S",
import numpy as np
def heuristic(n, rng=None):
if isinstance(rng, int):
rng = np.random.default_rng(rng)
elif rng is None:
rng = np.random.default_rng()
S = set()
scores = np.zeros(n+1, dtype=int)
for x in range(1, n+1):
scores[x] = sum(1 for y in S if 2*x - y in S or 2*y - x in S or x + y in S)
for _ in range(n):
candidates = [x for x in range(1, n+1) if x not in S and scores[x] == 0]
if not candidates:
break
x = min(candidates)
S.add(x)
for y in S:
if 2*x - y > 0 and 2*x - y <= n:
scores[2*x - y] += 1
if 2*y - x > 0 and 2*y - x <= n:
scores[2*y - x] += 1
if x + y > 0 and x + y <= n and (x + y) % 2 == 0:
scores[(x + y) // 2] += 1
return S