Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Determine the Order by blackfaced
from collections import defaultdict
def checkio(data):
graphs = defaultdict(set)
nodes = set([c for str in data for c in str ])
queues = []
def str_to_Topology(s):
chars = [c for c in s]
for i in range(len(chars)):
[graphs[c].add(chars[i]) for c in s[i+1:] if c != chars[i]]
[str_to_Topology(s) for s in data]
while nodes:
roots = sorted([c for c in nodes if len(graphs[c]) == 0])
root = roots[0]
queues.extend(root)
nodes.difference_update(root)
[graphs[c].discard(root) for c in nodes]
return "".join(queues)
#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"
May 23, 2013
Comments: