Код:
from itertools import * graf = 'ВАБГВЕЖДГБДЕ' table = [[0, 22, 28, 12, 0, 16, 0], [22, 0, 0, 11, 30, 0, 0], [28, 0, 0, 0, 0, 26, 20], [12, 11, 0, 0, 0, 0, 15], [0, 30, 0, 0, 0, 0, 18], [16, 0, 26, 0, 0, 0, 0], [0, 0, 20, 15, 18, 0, 0]] def f(x, y): x, y = p.index(x), p.index(y) return table[x][y] for p in permutations(set(graf)): if all((f(x, y) > 0) == (x+y in graf or y+x in graf) for x in p for y in p): #print(*p, sep='') print(f(*'АБ')+f(*'ЕЖ'))
ывмыммымымымывмымымымымывмы
Код:
фывфвфвфвфвфыв