Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moria Doors by dagger126
from string import punctuation
def find_word(message):
words = [i.strip(punctuation) for i in message.lower().split()]
result = []
for n, j in enumerate(words):
point = 0
for m, i in enumerate(words):
if n != m:
if j[0] == i[0]:
point += 10
if j[-1] == i[-1]:
point += 10
point += min(len(j), len(i)) / max(len(j), len(i)) * 30
point += len(set(j) & set(i)) / len(set(j) | set(i)) * 50
result.append((point, j))
return max(result[::-1])[1]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert find_word("Speak friend and enter.") == "friend", "Friend"
assert find_word("Beard and Bread") == "bread", "Bread is Beard"
assert find_word("The Doors of Durin, Lord of Moria. Speak friend and enter. "
"I Narvi made them. Celebrimbor of Hollin drew these signs") == "durin", "Durin"
assert find_word("Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy."
" According to a researcher at Cambridge University.") == "according", "Research"
assert find_word("One, two, two, three, three, three.") == "three", "Repeating"
Sept. 25, 2014
Comments: