import numpy as np
for n in (256, 512):
    e = np.load("npy/identity_N%d.npy" % n); c = n // 2
    def ring(half):
        a = e[c - half:c + half, c - half:c + half].copy(); a[1:-1, 1:-1] = -1; v = a[a >= 0]
        return {h: int((v == h).sum()) for h in range(4)}
    side = 2
    while (e[c - side // 2 - 1:c + side // 2 + 1, c - side // 2 - 1:c + side // 2 + 1] == 2).all(): side += 2
    print("N=%d all-2 square side %d" % (n, side))
    for s in range(side + 2, side + 9, 2):
        print("  ring at side %d: %s" % (s, ring(s // 2)))
    s = side + 2; h = s // 2; blk = e[c - h:c + h, c - h:c + h]
    bad = np.argwhere(blk != 2); print("  first ring non-2 cells (row,col within the %dx%d block):" % (s, s), bad[:12].tolist(), "... total", len(bad))
