Created
January 22, 2022 02:00
-
-
Save nishio/50776164d871096a32b877260bab6e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import perf_counter | |
from math import log | |
from collections import Counter | |
words = open("wordle_dictionary1.txt", "r").read().split() | |
words += open("wordle_dictionary2.txt", "r").read().split() | |
def test(trial, answer): | |
ret = [] | |
for i, c in enumerate(trial): | |
if c == answer[i]: | |
ret.append("H") | |
elif c in answer: | |
ret.append("b") | |
else: | |
ret.append("_") | |
return "".join(ret) | |
def main(hints=[]): | |
global ent_stat | |
filtered_words = words | |
for (q, a) in hints: | |
filtered_words = [w for w in filtered_words if test(q, w) == a] | |
if len(filtered_words) < 30: | |
print(filtered_words) | |
N = len(filtered_words) | |
ent_stat = [] | |
for trial in words: | |
count = Counter([test(trial, w) for w in filtered_words]) | |
# print(count) | |
entropy = 0 | |
for c in count: | |
p = count[c] / N | |
entropy += -p * log(p, 2) | |
ent_stat.append((entropy, trial)) | |
ent_stat.sort(reverse=True) | |
print(ent_stat[:10]) | |
t = perf_counter() | |
# * for initial trial | |
# main() | |
# => [(6.194052544375447, 'tares'), (6.149918742453126, 'lares'), (6.114343099454228, 'rales'), (6.096242642514602, 'rates'), (6.076619177276175, 'teras'), (6.066830765753897, 'nares'), (6.06139539909626, 'soare'), (6.054987761401192, 'tales'), (6.049777632888326, 'reais'), (6.032338670239807, 'tears')] | |
# ** Wordle 216 (demonstrated in https://twitter.com/nishio/status/1484204200137424896 ) | |
# * maximum entropy play | |
# main([("tares", "__b__")]) | |
# => [(5.148738326081236, 'bound'), (5.10768226567073, 'poind'), (5.106842549506799, 'coign'), (5.097007133831714, 'pound'), (5.086941406140314, 'lound'), (5.075261301916091, 'doing'), (5.072450206617732, 'bidon'), (5.048159132537879, 'prion'), (5.041341481967895, 'colin'), (5.034571953183442, 'could')] | |
# main([("tares", "__b__"), ("bound", "_____")]) | |
# => ['prick', 'crimp', 'privy', 'wryly', 'crick', 'grill', 'krill', 'frill', 'grimy', 'whirl', 'chirp', 'chirk', 'chirl', 'chirm', 'chirr', 'frizz', 'griff', 'gripy', 'pricy', 'prill', 'primi', 'primp', 'primy', 'vizir', 'whirr', 'wrick'] | |
# => [(3.6902603909683838, 'pilch'), (3.6573852766501784, 'crimp'), (3.6573852766501784, 'chimp'), (3.551428065028506, 'lymph'), (3.546593564294938, 'clype'), (3.53257325750262, 'pricy'), (3.53257325750262, 'clump'), (3.53257325750262, 'clomp'), (3.53257325750262, 'clamp'), (3.517559429596343, 'chelp')] | |
# main([("tares", "__b__"), ("bound", "_____"), ("pilch", "Hb_H_")]) | |
# => ['prick', 'pricy'] | |
# => [(1.0, 'zymic'), (1.0, 'zymes'), (1.0, 'zygon'), (1.0, 'zygal'), (1.0, 'zouks'), (1.0, 'zooty'), (1.0, 'zooks'), (1.0, 'zooey'), (1.0, 'zonks'), (1.0, 'zloty')] | |
# * human play | |
# main([("tares", "__b__"), ("right", "bb___"), | |
# ("irony", "bH___"), ("wrick", "_HHHH")]) | |
# => ['prick', 'crick', 'brick'] | |
# => [(1.584962500721156, 'upbye'), (1.584962500721156, 'upbow'), (1.584962500721156, 'rebop'), (1.584962500721156, 'pubis'), (1.584962500721156, 'pubic'), (1.584962500721156, 'pubes'), (1.584962500721156, 'pubco'), (1.584962500721156, 'probs'), (1.584962500721156, 'probe'), (1.584962500721156, 'pombe')] | |
# 0.13939706499513704 | |
print(perf_counter() - t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment