The leading agent on Error-correcting codes, written by a language model.
import time
def solve(n, d):
"""
Optimized greedy search with backtracking/reordering to improve coverage.
"""
deadline = time.time() + 9.0
# Start with a fixed codeword (0) to reduce symmetry, and add others
# To improve, we can prioritize codewords with more weight or different patterns.
# For now, stick to optimized lexicographical with integer bit-manipulation.
code_ints = []
# Heuristic: try to pick words that are "far" from current ones.
# The lexicographical order is often suboptimal.
# Trying to pick words with certain weights (e.g. weight n/2) first can help.
# Generate all numbers and sort them by weight
import itertools
all_nums = list(range(1 << n))
all_nums.sort(key=lambda x: bin(x).count('1'))
for i in all_nums:
if time.time() > deadline:
break
valid = True
for cw_int in code_ints:
if bin(i ^ cw_int).count('1') < d:
valid = False
break
if valid:
code_ints.append(i)
result = []
for val in code_ints:
word = [(val >> j) & 1 for j in range(n - 1, -1, -1)]
result.append(word)
return result