Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Moria Doors by yukirin
import re
from string import punctuation as punct
def likeness(a, b, coefficient=0):
la, lb = len(a), len(b)
if a[0] == b[0]: coefficient += 10
if a[-1] == b[-1]: coefficient += 10
coefficient += (la / lb if la <= lb else lb / la) * 30
coefficient += ((len(set(a)) + len(set(b)) - len(set(a + b))) / (len(set(a + b)))) * 50
return coefficient
def find_word(message):
msg_list = re.sub(r'[{0}]'.format(punct), ' ', message.lower()).split()
msg_list.reverse()
results = []
for i, w in enumerate(msg_list):
other_word = msg_list[:i] + msg_list[i + 1:]
results.append(sum(likeness(w, other) for other in other_word) / len(other_word))
return msg_list[results.index(max(results))]
April 10, 2015