"""Harder algorithmic repair families with independent small-instance oracles.""" import ast from fractions import Fraction def allocation_ref(workers,jobs,quotes): cost={(w,j):c for w,j,c in quotes} slots=[j for j,d in jobs for _ in range(d)] remaining=dict(workers) best=(0,0) def search(i,filled,total): nonlocal best if i==len(slots): if filled>best[0] or (filled==best[0] and total0 and (w,j) in cost: remaining[w]-=1 search(i+1,filled+1,total+cost[w,j]) remaining[w]+=1 search(0,0,0) return {'filled':best[0],'cost':best[1]} def expression_ref(text): # AST visitor is independent of the candidate's tokenizer/Pratt parser. tree=ast.parse(text.strip().replace('^','**'),mode='eval') def evaluate(n): if isinstance(n,ast.Constant) and type(n.value) is int: return Fraction(n.value) if isinstance(n,ast.UnaryOp): v=evaluate(n.operand) return -v if isinstance(n.op,ast.USub) else v a,b=evaluate(n.left),evaluate(n.right) if isinstance(n.op,ast.Add): return a+b if isinstance(n.op,ast.Sub): return a-b if isinstance(n.op,ast.Mult): return a*b if isinstance(n.op,ast.Div): return a/b if isinstance(n.op,ast.Pow): return a**b raise ValueError('operator') return str(evaluate(tree.body)) HARD_SPECS={ 'allocation': ( 'solve(workers,jobs,quotes): workers=[[name,capacity],...], jobs=[[name,demand],...], quotes=[[worker,job,cost_per_unit],...] (unique pairs, nonnegative integer costs). Unquoted assignments are forbidden. Allocate integer units, never exceed a worker capacity or job demand. First maximize total filled demand, then minimize cost among all such allocations. Return exactly {filled:int,cost:int}. A greedy edge ordering is insufficient; reassignment may be necessary. Names in each list are unique. Empty and disconnected instances are valid; do not mutate inputs.', { 'network.py': "def edge(graph,a,b,cap,cost):\n graph[a].append([b,len(graph[b]),cap,cost])\n graph[b].append([a,len(graph[a])-1,0,-cost])\n", 'paths.py': "def shortest(graph,source):\n n=len(graph)\n distance=[None]*n\n parent=[None]*n\n distance[source]=0\n for turn in range(n-1):\n changed=False\n for a in range(n):\n if distance[a] is not None:\n for idx,e in enumerate(graph[a]):\n b,rev,cap,cost=e\n if cap>0 and (distance[b] is None or distance[a]+cost