Skip to content

Commit db32621

Browse files
committed
rank wordle words with frequency score
1 parent c2144a5 commit db32621

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,29 @@ Top 3 letters per position
9696
| 'boast' |
9797
| 'crony' |
9898
| 'crone' |
99+
100+
All words with the top 8 letters for each position (and no duplicated letters), and with the top 10 digraphs:
101+
102+
<!-- ┌─────────┬─────────┐
103+
│ (index) │ Word │
104+
├─────────┼─────────┤
105+
│ 0 │ 'store' │
106+
│ 1 │ 'stair' │
107+
│ 2 │ 'stale' │
108+
│ 3 │ 'stare' │
109+
│ 4 │ 'steal' │
110+
│ 5 │ 'roast' │
111+
│ 6 │ 'stole' │
112+
│ 7 │ 'least' │
113+
└─────────┴─────────┘ -->
114+
115+
| All words with the top 8 letters for each position (and no duplicated letters), <br> and with one of the top 10 digraphs: |
116+
| ------------------------------------------------------------------------------------------------------------------------- |
117+
| 'store' |
118+
| 'stair' |
119+
| 'stale' |
120+
| 'stare' |
121+
| 'steal' |
122+
| 'roast' |
123+
| 'stole' |
124+
| 'least' |

dist/index.cjs

+99
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,105 @@ var topWordsByIndex = wordlist.filter((word) => {
23672367
console.log("All words with the top 3 letters for each position (and no duplicated letters):");
23682368
console.table(topWordsByIndex.map((word) => ({ Word: word })));
23692369
var wordle = "wordle";
2370+
var consonantDigraphs = [
2371+
"bl",
2372+
"br",
2373+
"ch",
2374+
"ck",
2375+
"cl",
2376+
"cr",
2377+
"dr",
2378+
"fl",
2379+
"fr",
2380+
"gh",
2381+
"gl",
2382+
"gr",
2383+
"ng",
2384+
"ph",
2385+
"pl",
2386+
"pr",
2387+
"qu",
2388+
"sc",
2389+
"sh",
2390+
"sk",
2391+
"sl",
2392+
"sm",
2393+
"sn",
2394+
"sp",
2395+
"st",
2396+
"sw",
2397+
"th",
2398+
"tr",
2399+
"tw",
2400+
"wh",
2401+
"wr",
2402+
"nth",
2403+
"sch",
2404+
"scr",
2405+
"shr",
2406+
"spl",
2407+
"spr",
2408+
"squ",
2409+
"str",
2410+
"thr",
2411+
"ai",
2412+
"au",
2413+
"aw",
2414+
"ay",
2415+
"ea",
2416+
"ee",
2417+
"ei",
2418+
"eu",
2419+
"ew",
2420+
"ey",
2421+
"ie",
2422+
"oi",
2423+
"oo",
2424+
"ou",
2425+
"ow",
2426+
"oy"
2427+
];
2428+
var digraphCount = wordlist.reduce((all, curr) => {
2429+
consonantDigraphs.forEach((digraph) => {
2430+
if (curr.includes(digraph)) {
2431+
if (all == null ? void 0 : all[digraph]) {
2432+
all[digraph]++;
2433+
} else {
2434+
all[digraph] = 1;
2435+
}
2436+
}
2437+
});
2438+
return all;
2439+
}, {});
2440+
var sortedDigraphCount = Object.entries(digraphCount).sort((a, b) => b[1] - a[1]);
2441+
console.log("Digraph Count:", sortedDigraphCount.map(([digraph, count]) => ({
2442+
Digraph: digraph,
2443+
Count: count
2444+
})));
2445+
var wordsWithDigraphAndTopLetters = wordlist.filter((word) => {
2446+
return word.split("").every((c, i) => {
2447+
return countOrder.slice(0, 8).map(([letter]) => letter).includes(c);
2448+
}) && sortedDigraphCount.slice(0, 10).some(([digraph]) => {
2449+
return word.includes(digraph);
2450+
}) && (/* @__PURE__ */ new Set([...word.split("")])).size === 5;
2451+
});
2452+
console.log("All words with the top 8 letters for each position (and no duplicated letters), and with the top 10 digraphs:");
2453+
console.table(wordsWithDigraphAndTopLetters.map((word) => ({ Word: word })));
2454+
var getWordScore = (list) => list.reduce((all, curr) => {
2455+
const score = curr.split("").reduce((total, letter) => {
2456+
return total + countOrder.findIndex(([l]) => l === letter);
2457+
}, 0);
2458+
if ((/* @__PURE__ */ new Set([...curr.split("")])).size === 5) {
2459+
all[curr] = score;
2460+
}
2461+
return all;
2462+
}, {});
2463+
var wordScoreDigraphs = getWordScore(wordsWithDigraphAndTopLetters);
2464+
var sortedWordScoreDigraphs = Object.entries(wordScoreDigraphs).sort((a, b) => b[1] - a[1]);
2465+
console.log("Word Score:", sortedWordScoreDigraphs.map(([word, score]) => ({ Word: word, Score: score })));
2466+
var wordScore = getWordScore(wordlist);
2467+
var sortedWordScore = Object.entries(wordScore).sort((a, b) => b[1] - a[1]).reverse().slice(0, 30);
2468+
console.log("Word Score:", sortedWordScore.map(([word, score]) => ({ Word: word, Score: score })));
23702469

23712470
// src/index.ts
23722471
console.log(wordle);

src/wordle/wordle.ts

+145
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,148 @@ console.table(topWordsByIndex.map((word) => ({ Word: word })))
9393
// const commonWords = topWordsByIndex.filter((word) => topWords.includes(word))
9494
// console.table(commonWords.map((word) => ({ Word: word })))
9595
export const wordle = "wordle"
96+
97+
const consonantDigraphs = [
98+
// digraphs
99+
"bl",
100+
"br",
101+
"ch",
102+
"ck",
103+
"cl",
104+
"cr",
105+
"dr",
106+
"fl",
107+
"fr",
108+
"gh",
109+
"gl",
110+
"gr",
111+
"ng",
112+
"ph",
113+
"pl",
114+
"pr",
115+
"qu",
116+
"sc",
117+
"sh",
118+
"sk",
119+
"sl",
120+
"sm",
121+
"sn",
122+
"sp",
123+
"st",
124+
"sw",
125+
"th",
126+
"tr",
127+
"tw",
128+
"wh",
129+
"wr",
130+
// trigraphs
131+
"nth",
132+
"sch",
133+
"scr",
134+
"shr",
135+
"spl",
136+
"spr",
137+
"squ",
138+
"str",
139+
"thr",
140+
// vowel digraphs
141+
"ai",
142+
"au",
143+
"aw",
144+
"ay",
145+
"ea",
146+
"ee",
147+
"ei",
148+
"eu",
149+
"ew",
150+
"ey",
151+
"ie",
152+
"oi",
153+
"oo",
154+
"ou",
155+
"ow",
156+
"oy",
157+
]
158+
159+
// count occurrences of digraphs
160+
const digraphCount = wordlist.reduce((all: LetterCount, curr) => {
161+
consonantDigraphs.forEach((digraph) => {
162+
if (curr.includes(digraph)) {
163+
if (all?.[digraph]) {
164+
all[digraph]++
165+
} else {
166+
all[digraph] = 1
167+
}
168+
}
169+
})
170+
return all
171+
}, {})
172+
const sortedDigraphCount = Object.entries(digraphCount).sort(
173+
(a, b) => b[1] - a[1]
174+
)
175+
console.log(
176+
"Digraph Count:",
177+
sortedDigraphCount.map(([digraph, count]) => ({
178+
Digraph: digraph,
179+
Count: count,
180+
}))
181+
)
182+
183+
const wordsWithDigraphAndTopLetters = wordlist.filter((word) => {
184+
return (
185+
word.split("").every((c) => {
186+
return (
187+
countOrder
188+
// use top 8 letters
189+
.slice(0, 8)
190+
.map(([letter]) => letter)
191+
.includes(c)
192+
)
193+
}) &&
194+
// top 5 digraphs
195+
sortedDigraphCount.slice(0, 10).some(([digraph]) => {
196+
return word.includes(digraph)
197+
}) &&
198+
new Set([...word.split("")]).size === 5
199+
)
200+
// consonantDigraphs.slice(0, 5).some((digraph) => word.includes(digraph)) &&
201+
// new Set([...word.split("")]).size === 5
202+
// )
203+
})
204+
console.log(
205+
"All words with the top 8 letters for each position (and no duplicated letters), and with the top 10 digraphs:"
206+
)
207+
console.table(wordsWithDigraphAndTopLetters.map((word) => ({ Word: word })))
208+
209+
// word score
210+
const getWordScore = (list: Readonly<string[]>) =>
211+
list.reduce((all: LetterCount, curr) => {
212+
const score = curr.split("").reduce((total, letter) => {
213+
return total + countOrder.findIndex(([l]) => l === letter)
214+
}, 0)
215+
if (new Set([...curr.split("")]).size === 5) {
216+
all[curr] = score
217+
}
218+
return all
219+
}, {})
220+
221+
const wordScoreDigraphs = getWordScore(wordsWithDigraphAndTopLetters)
222+
223+
const sortedWordScoreDigraphs = Object.entries(wordScoreDigraphs).sort(
224+
(a, b) => b[1] - a[1]
225+
)
226+
console.log(
227+
"Word Score:",
228+
sortedWordScoreDigraphs.map(([word, score]) => ({ Word: word, Score: score }))
229+
)
230+
231+
const wordScore = getWordScore(wordlist)
232+
const sortedWordScore = Object.entries(wordScore)
233+
.sort((a, b) => b[1] - a[1])
234+
.reverse()
235+
.slice(0, 30)
236+
237+
console.log(
238+
"Word Score:",
239+
sortedWordScore.map(([word, score]) => ({ Word: word, Score: score }))
240+
)

0 commit comments

Comments
 (0)