Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
algorithmic_improvement solution in Speedy category for Determine the Order by KareeO
import re
def dominate(a,b,data):
if a==b or any(re.search(a+'\w*'+b, w) for w in data): return True
else:
amis = [c for c in format([ t[t.index(a)+1:] for t in data if a in t]) if c.isalpha() ]
return any(dominate(c,b, [j for j in data if a not in j]) for c in amis)
def checkio(data):
data = [s for s in data if s]
if not data: return ''
headers = [s[0] for s in data]
head = min([s for s in headers if not any([dominate(h,s,data) for h in headers if h!=s])])
return head + checkio([s.strip(head) for s in data if s[0] == head]+[s for s in data if s[0] != head])
#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"
April 16, 2020