Fixed bug in search algorythm
This commit is contained in:
parent
4c32c46982
commit
0c5f581668
1 changed files with 9 additions and 10 deletions
19
findpsy.py
19
findpsy.py
|
@ -19,22 +19,22 @@ start = 0;
|
||||||
all_paths = []
|
all_paths = []
|
||||||
|
|
||||||
def deep (path, result):
|
def deep (path, result):
|
||||||
for i in range(path[-1], len(matrix[0])):
|
|
||||||
if matrix[path[-1]][i] == 0:
|
if all(v > 0 for v in result):
|
||||||
|
print "PATH: {0}".format(path)
|
||||||
|
all_paths.append(path)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
for i in range(path[-1], len(result)):
|
||||||
|
if result[i] == 0:
|
||||||
new_path = list(path)
|
new_path = list(path)
|
||||||
new_result = list(result)
|
new_result = list(result)
|
||||||
|
|
||||||
new_path.append(i)
|
new_path.append(i)
|
||||||
|
|
||||||
for j in range(0, len(new_result)):
|
for j in range(0, len(new_result)):
|
||||||
new_result[j] = new_result[j] | matrix[i][j]
|
new_result[j] = new_result[j] | matrix[i][j]
|
||||||
|
|
||||||
if all(v > 0 for v in new_result):
|
deep (new_path, new_result)
|
||||||
print "PATH: {0}".format(new_path)
|
|
||||||
all_paths.append(new_path)
|
|
||||||
return 1
|
|
||||||
else:
|
|
||||||
deep (new_path, new_result)
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ def deep (path, result):
|
||||||
f = open (sys.argv[1])
|
f = open (sys.argv[1])
|
||||||
matrix = [ map(int,line.split(';')) for line in f ]
|
matrix = [ map(int,line.split(';')) for line in f ]
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
my_path = [ start ]
|
my_path = [ start ]
|
||||||
my_result = list(matrix[start])
|
my_result = list(matrix[start])
|
||||||
|
|
Loading…
Reference in a new issue