-
Notifications
You must be signed in to change notification settings - Fork 1
/
entropy_all.py
35 lines (29 loc) · 1.26 KB
/
entropy_all.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
from collections import defaultdict
import itertools
from multiprocessing import Pool, cpu_count
from wordle import Wordle
def compute_entropy(guess, wordle):
marks = defaultdict(int)
for target in wordle.all_words: # iter through whole list
_, mark, _, _, _ = wordle.get_guess_result(target, guess)
marks[''.join(mark)] += 1
entropy = wordle.compute_entropy(marks)
dict_en = {guess: entropy}
return dict_en
if __name__ == '__main__':
wordle = Wordle()
# dict_en = {}
# for guess in wordle.all_words[:100]: # iter through whole list
# marks = defaultdict(int)
# for target in wordle.all_words[:100]: # iter through whole list
# _, mark, _, _, _ = wordle.get_guess_result(target, guess)
# marks[''.join(mark)] += 1
# entropy = wordle.compute_entropy(marks)
# dict_en[guess] = entropy
with Pool(cpu_count()) as pool:
dict_en = pool.starmap(compute_entropy, [(guess, wordle) for guess in wordle.all_words])
dict_en = dict(itertools.chain(*map(dict.items, dict_en)))
with open('5letter_2315_entropy.txt', 'w') as f:
for k in sorted(dict_en, key=dict_en.get, reverse=True):
s = k + ' ' + str(round(dict_en[k], 3)) + '\n'
f.write(s)