1
I made a backtracking program in Python to find a set of M-sized binary strings where any string has a distance greater than d to any other string in the set.
But it does not work well when I test for n = 8. Message appears:
"Runtime error! This application has requested the Runtime to terminate it in an Unusual way"
Does anyone know why?
Code:
def dist(a,b):
k = 0
for i in range (0,20):
if a%2 != b%2:
k = k + 1
a = a/2
b = b/2
return k
def bin(n):
nd = 0
pot = 1
while (n 0):
nd = nd + n%2 * pot
n = n/2
pot = pot * 10
return nd
o = []
o = o + [0]
M = 4
n = 5
d = 3
Tam = 2**n - 1
def cod(ult):
j = ult
while j < Tam+1:
aux = 0
for i in range (0,len(o)):
if dist(o[i],j+1) d-1:
aux += 1
if aux == len(o):
o.append(j+1)
j +=1
else:
j+=1
return (o)
cod(0)
while len(o) < M+1:
if len(o) M-1:
for i in range (0,len(o)):
print bin(o[i])
print o
print len(o)
break
else:
ult = o.pop()
cod(ult)
Changed
n = 5
forn = 8
, tested and no error occurred.– Luiz Vieira
Which version of python you are using?
– brow-joe
Yes, Luiz, with lower values of n, no error occurs. I have installed version 2.7 and also tried to run online in repl.it and hangs at some point...
– Natália