def priority(el, n):
"""Computes the priority score based on the given tuple and integer."""
score = n
in_el = 0
el_count = el.count(0)
if el_count == 0:
score += n**2
if el[1] == el[-1]:
score *= 1.5
if el[2] == el[-2]:
score *= 1.5
if el[3] == el[-3]:
score *= 1.5
else:
if el[1] == el[-1]:
score *= 0.5
if el[2] == el[-2]:
score *= 0.5
for e in el:
if e == 0:
if in_el == 0:
score *= n * 0.5
elif in_el == el_count - 1:
score *= 0.5
else:
score *= n * 0.5 ** in_el
in_el += 1
else:
score += 1
if el[1] == el[-1]:
score *= 1.5
if el[2] == el[-2]:
score *= 1.5
return score
import numpy as np
import itertools
def build_512_cap():
"""Returns a cap set of size 512 in `n=8` dimensions."""
n = 8
V = np.array(list(itertools.product(range(3), repeat=n)), dtype=np.int32)
def support(v):
return tuple(i for i in range(n) if v[i] != 0)
def reflections(v):
return sum(1 for i in range(1, n//2) if v[i] == v[-i])
# Add all 128 weight-8 vectors that have >= 2 reflections.
weight8_vectors = [v for v in V
if np.count_nonzero(v) == 8 # Weight is 8.
and reflections(v) >= 2] # At least 2 reflections.
# Add all 128 weight-4 vectors that have specific support.
supports_16 = [(0, 1, 2, 3), (0, 1, 2, 5), (0, 3, 6, 7), (0, 5, 6, 7),
(1, 3, 4, 6), (1, 4, 5, 6), (2, 3, 4, 7), (2, 4, 5, 7)]
weight4_vectors = [v for v in V if support(v) in supports_16]
# Add all 128 weight-4 vectors with specific support and 1 reflection.
supports_8 = [(0, 1, 2, 7), (0, 1, 2, 6), (0, 1, 3, 7), (0, 1, 6, 7),
(0, 1, 5, 7), (0, 2, 3, 6), (0, 2, 6, 7), (0, 2, 5, 6),
(1, 2, 4, 7), (1, 2, 4, 6), (1, 3, 4, 7), (1, 4, 6, 7),
(1, 4, 5, 7), (2, 3, 4, 6), (2, 4, 6, 7), (2, 4, 5, 6)]
weight4_vectors_2 = [v for v in V if support(v) in supports_8
and reflections(v) == 1] # Exactly 1 reflection.
# Add 128 weight-5 vectors with <= 1 reflections and one more condition.
allowed_zeros = [(0, 4, 7), (0, 2, 4), (0, 1, 4), (0, 4, 6),
(1, 2, 6), (2, 6, 7), (1, 2, 7), (1, 6, 7)]
weight5_vectors = [
v for v in V
if tuple(i for i in range(n) if v[i] == 0) in allowed_zeros
and reflections(v) <= 1 # At most 1 reflection.
and (v[1] != v[7]) % 3 != 1 and (v[2] != v[6]) % 3 != 1
]
return weight8_vectors + weight4_vectors + weight4_vectors_2 + weight5_vectors