46 lines
919 B
Python
46 lines
919 B
Python
def generateOutput(inputword, correct):
|
|
res = [0, 0, 0, 0, 0]
|
|
for i in range(len(inputword)):
|
|
if inputword[i] == correct[i]:
|
|
res[i] = 2
|
|
elif inputword[i] in correct:
|
|
res[i] = 1
|
|
|
|
return tuple(res)
|
|
|
|
def probs(dataset):
|
|
res = {}
|
|
for i in dataset:
|
|
if i in res:
|
|
res[i] += 1
|
|
else:
|
|
res[i] = 1
|
|
return res
|
|
|
|
def dist(dataset):
|
|
buf = []
|
|
for i in dataset:
|
|
tot = 0
|
|
nums = 0
|
|
for j in dataset[i]:
|
|
tot += dataset[i][j]
|
|
nums += 1
|
|
buf.append([i, tot / nums])
|
|
buf.sort(key = lambda x: x[1])
|
|
|
|
return buf
|
|
|
|
def runtime(dataset):
|
|
return len(dataset) * len(dataset)
|
|
|
|
def main(words):
|
|
data = {}
|
|
|
|
for i in words:
|
|
cache = []
|
|
for j in words:
|
|
cache.append(generateOutput(i, j))
|
|
data[i] = probs(cache)
|
|
|
|
return dist(data)
|