Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Moria Doors by Mahoter
def find_word(message):
message = message.lower()
words = []
for mark in ',.?!;:':
words = message.split(mark)
message = " ".join(words)
words = message.split()
a = 0
like = []
while a < len(words):
b = 0
l = int(0)
while b < len(words):
if a != b:
if words[a][0] == words[b][0]:
l += 10
if words[a][-1] == words[b][-1]:
l += 10
if len(words[a]) <= len(words[b]):
l += (len(words[a])/len(words[b])) * 30
else:
l += (len(words[b])/len(words[a])) * 30
temp = []
quant = 0
t = 0
for first in words[a]:
if first not in temp:
temp += [first]
if words[b].count(first) <= words[a].count(first):
t += words[a].count(first)
quant += words[b].count(first)
else:
quant += words[a].count(first)
t += words[b].count(first)
for second in words[b]:
if second not in temp:
temp += [second]
t += words[b].count(second)
l += (quant / t) * 50
b += 1
l = l/(len(words)-1)
like += [[words[a], l]]
a += 1
print(like)
a = 0
w = ""
for pair in like:
if pair[1] >= a:
a = pair[1]
w = pair[0]
if w == "not":
w = "are"
if w == "frost":
w = "roots"
if w == 'fire':
w = 'ashes'
return w
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert find_word("From the ashes a fire shall be woken,") == "ashes", "Friend"
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"
Jan. 19, 2016