I'm trying to compare three different decoders for Hamming codes in python: brute force, local search, and syndrome. I am having issues with my brute force implementation:
def bruteForce(v):
n = len(v)
r = int(math.log(n+1,2))
k = n-r
m = []
d = []
c = []
for i in range(2**k):
m.append(decimalToVector(i,k))
for j in range(2**k):
d.append(hammingDistance(matrixMult(m[j], HammingG(r)),v))
for l in range(2**k):
if d[l] <= 1:
c = matrixMult(m[l], HammingG(r))
return c
This runs without error, but the output is simply []
, instead of any sequence of binary numbers, when the input is a vector such as bruteForce([1,0,0,0,0,0,1])
.
[]
unexpected as output? If so, why do you initialize c to[]
? In your code, the value returned is either this empty list (ifd[l] > 1
for alll
), or the result of the last computation in the last loop. – Armin Rigo