Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
TreeSearch(BFS) solution in Clear category for Determine the Order by Kouri
def checkio(data):
sol = []
def explore_tree(state, possib):
if len(sol)==0:
for char in sorted(set(''.join(possib))):
if not sum(elem.index(char) < elem.index(past_char) for past_char in state for elem in data if char in elem and past_char in elem):
if possib-set(char):
explore_tree(state+char, possib-set(char))
else:
sol.append(state+char)
for char in sorted(set(list(zip(*data))[0])):
if len(sol)==0:
explore_tree(char, set(''.join(data))-set(char))
return sol[0]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(["acb", "bd", "zwa"]) == "zwacbd", \
"Just concatenate it"
assert checkio(["klm", "kadl", "lsm"]) == "kadlsm", \
"Paste in"
assert checkio(["a", "b", "c"]) == "abc", \
"Cant determine the order - use english alphabet"
assert checkio(["aazzss"]) == "azs", \
"Each symbol only once"
assert checkio(["dfg", "frt", "tyg"]) == "dfrtyg", \
"Concatenate and paste in"
July 18, 2018