pure python for comparison

This commit is contained in:
Miguel M 2023-02-28 21:20:06 +00:00
parent 39cfb20f13
commit f420690041
1 changed files with 75 additions and 0 deletions

75
pytest/pure.py Normal file
View File

@ -0,0 +1,75 @@
import itertools
from math import inf
n = 16
k = 6
p = 2
def in_set_a(x):
return x.bit_count() == k
def in_set_b(y):
return y.bit_count() == k + 1
def related(a, b):
return (x ^ y).bit_count() == 1
m = inf
m_prime = inf
window = (1 << p) - 1
l = 0
l_prime = 0
# Look at all the `x`s, find the `x` with least number of relations, and
# what is the `x` with most relations (under the window condition)
for x in range(2**n):
if not in_set_a(x):
continue
relations_count = 0
for y in range(2**n):
if not in_set_b(y):
continue
if not related(x, y):
continue
relations_count += 1
if (x & window) != (y & window):
l += 1
# This `x` has less relations than all `x` we've looked at so far
if relations_count < m:
m = relations_count
for y in range(2**n):
if not in_set_b(y):
continue
relations_count = 0
for x in range(2**n):
if not in_set_a(x):
continue
if not related(x, y):
continue
relations_count += 1
if (x & window) != (y & window):
l_prime += 1
# This `y` has less relations than all `y` we've looked at so far
if relations_count < m_prime:
m_prime = relations_count
# Finally, see if we can get a better `l_max` under this window than
# what we've seen so far
l_max = l * l_prime
print(m, m_prime, l_max)