python3 <<'PY' import math a=0.25; b=1.0/12 def Arows(y1,y2): q=a+b-y1; q2=b+a-y2 return math.sqrt(a*a*q)+math.sqrt(max(0,b*q*(q-a)))+math.sqrt(b*b*q2)+math.sqrt(max(0,a*q2*(q2-b))) def Acols(y1,y2): q=a+b; q2=2*a+2*b-y1-y2-q return math.sqrt(q)*(a+b)+math.sqrt(max(0,q2))*(math.sqrt(max(0,b*(b-y1)))+math.sqrt(max(0,a*(a-y2)))) def BC(y1,y2): best=-1 for j in range(201): y3=a*j/200 beta=a+b-y3; B=math.sqrt(beta)*(b+math.sqrt(max(0,a*(a-y3)))) gam=y1+y2+y3; C=math.sqrt(gam)*(math.sqrt(max(0,b*y1))+math.sqrt(max(0,a*y2))+math.sqrt(max(0,a*y3))) if B+C>best: best=B+C return best for name,fn in [("rows",Arows),("cols",Acols)]: best=-1; arg=None for i in range(31): y1=b*i/30 for j in range(31): y2=a*j/30 A=fn(y1,y2) tot=A+BC(y1,y2) if tot>best: best=tot; arg=(y1,y2,A,tot) print(name,best,arg,"1-best",1-best) PY