Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
C3-like solution in Clear category for Determine the Order by tom-tom
def checkio(data):
words = sorted(''.join(sorted(set(w), key=w.index)) for w in data if w)
result = ''
while words:
for word in words:
c = word[0]
if all(c not in w[1:] for w in words):
break
result += c
words = sorted(w if w[0] != c else w[1:] for w in words if w != c)
return result
#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"
Oct. 25, 2016
Comments: