Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
String based, simple solution in Speedy category for Determine the Order by percevalve
def checkio(data):
output = ""
mine = data
#Just listing the letters initially present
all_the_letters = "".join(sorted(list(set(x for i in data for x in i))))
while len(all_the_letters)>0:
for letter in all_the_letters:
if all(word.find(letter) < 1 for word in mine):
output += letter
break
mine = [(word,"".join(word.split(letter)))[word.find(letter) == 0] for word in mine]
all_the_letters = "".join(all_the_letters.split(letter))
return output
#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"
def checkio(data):
result=[]
strings=data
while 1:
letters=get_letters(strings)
if letters==[]: break
for letter in letters:
positions=get_positions(strings,letter)
if positions==[0]:
result.append(letter)
strings=remove_letter(strings,letter)
return ''.join(result)
def get_letters(strings):
return sorted(set(''.join(strings)))
def get_positions(strings,letter):
positions=[string.find(letter) for string in strings]
positions=[position for position in positions if position!=-1]
positions=sorted(set(positions))
return positions
def remove_letter(strings,letter):
strings=[string.replace(letter,'') for string in strings]
strings=[string for string in strings if string!='']
return strings
#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"
Sept. 4, 2014