From 0c5f581668940eb7592d342b5d1bf6671255d5b8 Mon Sep 17 00:00:00 2001 From: AlexVanin Date: Thu, 17 Mar 2016 17:58:52 +0300 Subject: [PATCH] Fixed bug in search algorythm --- findpsy.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/findpsy.py b/findpsy.py index 794c176..b789d04 100755 --- a/findpsy.py +++ b/findpsy.py @@ -19,22 +19,22 @@ start = 0; all_paths = [] 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_result = list(result) - new_path.append(i) for j in range(0, len(new_result)): new_result[j] = new_result[j] | matrix[i][j] - if all(v > 0 for v in new_result): - print "PATH: {0}".format(new_path) - all_paths.append(new_path) - return 1 - else: - deep (new_path, new_result) + deep (new_path, new_result) return 0 @@ -42,7 +42,6 @@ def deep (path, result): f = open (sys.argv[1]) matrix = [ map(int,line.split(';')) for line in f ] - while True: my_path = [ start ] my_result = list(matrix[start])