-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwordstringplay.py
More file actions
115 lines (89 loc) · 3.05 KB
/
wordstringplay.py
File metadata and controls
115 lines (89 loc) · 3.05 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import random
openfile = open("../wordleweb/wordlists/words_alpha.txt", mode="r")
longdict = {}
for line in openfile:
line = line.strip()
if len(line) == 5:
longdict[line] = 1
openfile.close()
print(len(longdict))
longdictlist = list(longdict.keys())
print(longdictlist[1:5])
openfile = open("../wordleweb/wordlists/common5letter.txt", mode="r")
commonwords = []
for line in openfile:
line = line.strip()
if len(line) == 5:
commonwords.append(line)
openfile.close()
vowels = list("aeiou")
def generate_wordchain(onevowel=False):
wordchain: list[str] = []
lettersused = []
totaltries = 0
pickword = ""
# main loop to start here
for count in range(5):
lettersused += list(pickword)
for tries in range(5000):
pickword = random.choice(commonwords)
totaltries += 1
ok = True
vowelcount = 0
for idx, l in enumerate(pickword):
if l in vowels: vowelcount += 1
if l in lettersused or l in pickword[idx + 1:]: ok = False
if onevowel and vowelcount > 1: ok = False
if ok: break
# finished choosing a word
if not ok: break # would get here because ran out of tries
wordchain.append(pickword)
if len(wordchain) > 3: print(totaltries, wordchain)
return wordchain
def generate_wordchain_londict(onevowel=False):
wordchain: list[str] = []
lettersused = []
totaltries = 0
pickword = ""
# main loop to start here
for count in range(6):
lettersused += list(pickword)
for tries in range(5000):
pickword = random.choice(longdictlist)
totaltries += 1
ok = True
vowelcount = 0
for idx, l in enumerate(pickword):
if l in vowels: vowelcount += 1
if l in lettersused or l in pickword[idx + 1:]: ok = False
if onevowel and vowelcount > 1: ok = False
if ok: break
# finished choosing a word
if not ok: break # would get here because ran out of tries
wordchain.append(pickword)
if len(wordchain) > 3: print(totaltries, wordchain)
return wordchain
# londdict version
bestresult = []
fourormore = 0
for big_tries in range(500):
wordchain = generate_wordchain_londict(onevowel=True)
if len(wordchain) > len(bestresult):
bestresult = wordchain
if len(wordchain) >= 4: fourormore += 1
print("**LONGDICT***BEST OVERALL**: ", bestresult)
print("4 or more:", fourormore)
# common word version
bestresult = []
fourormore = 0
for big_tries in range(500):
wordchain = generate_wordchain(onevowel=True)
if len(wordchain) > len(bestresult):
bestresult = wordchain
if len(wordchain) >= 4: fourormore += 1
print("**COMMONDICT -- BEST OVERALL**: ", bestresult)
print("4 or more:", fourormore)
# END