-
Notifications
You must be signed in to change notification settings - Fork 4
/
stats.py
38 lines (31 loc) · 937 Bytes
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from collections import defaultdict
import json
words = []
with open("words.txt") as f:
for line in f:
words.append(line.strip())
with open("solution.json") as f:
solution = json.load(f)
distances = []
hist = defaultdict(int)
longestdistance = 0
def find(word, tree=solution, depth=1):
if tree["guess"] == word:
return depth
if "result" in tree:
for result in tree["result"]:
newtree = tree["result"][result]
dep = find(word, newtree, depth+1)
if dep != None:
return dep
return None
for word in words:
distance = find(word)
distances.append(distance)
hist[distance] += 1
if distance > longestdistance:
longestdistance = distance
print("Average:", sum(distances) / len(distances))
print("Worst:", longestdistance)
for i in sorted(hist.keys()):
print(f"{i}: {hist[i]} ({round(100*hist[i]/len(words), 1)}%)")