Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_value(l, value):
- result = []
- for i, val in enumerate(l):
- if value == val:
- result.append(i)
- return result
- def edges_counter(edges):
- result = len(edges[0])
- for i in range(0, len(edges[0])):
- start_point = edges[0][i]
- end_point = edges[1][i]
- for j in range(0, len(edges[0])):
- if start_point == edges[1][j] and end_point == edges[0][j]:
- result -= 0.5
- return int(result)
- def incorrect_remove(ways):
- del_ways = []
- for way in ways:
- for i_f in range(0, len(way)-1):
- first_edges = [way[i_f] + way[i_f+1], way[i_f+1] + way[i_f]]
- for i_s in range(0, len(way)-1):
- if i_f != i_s and way[i_s] + way[i_s+1] in first_edges and way[i_s+1] + way[i_s] in first_edges:
- del_ways.append(way)
- del_ways = list(set(del_ways))
- for d_way in del_ways:
- ways.remove(d_way)
- def printer(ways):
- for way in ways:
- if way[0] == way[-1]:
- way_print = ""
- for i in range(0, len(way)):
- way_print += str(int(way[i])+1)
- print(way_print)
- start_point = int(input("Начальная точка: ")) - 1
- m_size = int(input("Размер матрицы: "))
- matric = []
- for i in range(0, m_size):
- converted_string = []
- for num in input("Введите " + str(i + 1) + " срочку матрицы: ").split(" "):
- converted_string.append(int(num))
- matric.append(converted_string)
- edges = [[], []]
- for i_string in range(0, m_size):
- for i_val in range(0, m_size):
- if matric[i_string][i_val] == 1:
- edges[0].append(str(i_string))
- edges[1].append(str(i_val))
- ways = [str(start_point)]
- while(len(ways[0]) <= edges_counter(edges)):
- update_ways = []
- for i_way in range(0, len(ways)):
- for i_edge in find_value(edges[0], ways[i_way][-1]):
- update_ways.append(ways[i_way] + str(edges[1][i_edge]))
- ways = update_ways[:]
- incorrect_remove(ways)
- printer(ways)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement