我想把我最初的尝试作为第一个答案,但网站封锁了我大约8个小时,我现在只能回复。我把代码分成了更重要的片段。在
这是我目前为止的尝试:
我想我应该对下面的代码执行以下修改:1) Use dicts so that I have 0:000,1:001,... to improve the indexing.
2) Take the comparison string, adapt it to a list of all possible options
then compare this to the full binary list e.g. 010 becomes 110,000,011
and this is then is compared to the full binary list.
我尝试创建一个二进制数的列表如下(还没有使用dicts)
^{pr2}$
然后运行for循环,将每个字符串与其他字符串(当前不是最佳字符串)进行比较def GreySets(Bins):
for Bin1 in Bins :
for Bin2 in Bins :
stringXOR(Bin1,Bin2)
我从互联网上的其他人那里得到的字符串XOR,它返回一个truefalse true(我需要它来重新运行不匹配的位数)def stringXOR(a, b):
# Error Checking
msg = "Strings do not have same length: %d, %d!"
assert len(a) == len(b), msg % (len(a), len(b))
cnt = len(a) - 1
# Code
result = ''
while cnt + 1:
result = `(a[cnt] != b[cnt])` + result
cnt = cnt - 1
return result