Runtime Error in Python

Asked

Viewed 813 times

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 for n = 8, tested and no error occurred.

  • Which version of python you are using?

  • 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...

1 answer

1


according to the report there is a bug present in Python version 2.6, basically a solution to this problem was changing the path of the pythonhome environment variable from python26 to python32

  • I use version 2.7. Would it still be a solution? (I don’t understand much...)

  • I believe it would be the same solution, you need to enter the environment variables and change the value of the variable pythonhome python26 to python32 folder usually in Windows the folder gets in C:/.../python26 and C:/.../python32

  • Look, I think it worked. It’s been running for a long time and there’s no mistake. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.