How I found a good opener for Wordle
Like some other people, I played Wordle the last days. Today, I wrote a little tool to find out whats can be a good opener. Jotto is a similar game so it’s easy to find a list of words like this https://www.easysurf.cc/list1.htm
I downloaded and checked it against my helper tool. The code is not a beauty but it works (and I hope correctly)
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
checkAgainstWordlist()
}
func checkAgainstWordlist() {
lettercount := make(map[string]int)
file, err := os.Open("Wordlist")
if err != nil {
panic(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
for _, letter := range scanner.Text() {
if val, ok := lettercount[rune2c(letter)]; ok {
lettercount[rune2c(letter)] = val + 1
} else {
lettercount[rune2c(letter)] = 1
}
}
}
fmt.Println(rankByWordCount(lettercount))
if err := scanner.Err(); err != nil {
panic(err)
}
}
func rune2c(r rune) string {
return fmt.Sprintf("%c", r)
}
// https://stackoverflow.com/questions/18695346/how-can-i-sort-a-mapstringint-by-its-values
func rankByWordCount(wordFrequencies map[string]int) PairList {
pl := make(PairList, len(wordFrequencies))
i := 0
for k, v := range wordFrequencies {
pl[i] = Pair{k, v}
i++
}
sort.Sort(sort.Reverse(pl))
return pl
}
type Pair struct {
Key string
Value int
}
type PairList []Pair
func (p PairList) Len() int {
return len(p)
}
func (p PairList) Less(i, j int) bool {
return p[i].Value < p[j].Value
}
func (p PairList) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
The result was
[{e 709} {a 679} {r 565} {t 499} {i 480} {o 457} {s 429} {l 428} {n 418} {c 352} {u 335} {h 302} {d 258} {p 240} {y 238} {m 222} {g 203} {b 185} {k 154} {w 137} {f 137} {v 99} {x 30} {q 26} {z 24} {j 19}]
(e = 709 times, a = 679 times, …)
That means e,a,r,t, and i are the most used letters in the list. A word for this combination of letters can be IRATE
.
Update 14.01.2022
I got the Wordlist from Wordle itself and run my code again. The result are:
[{s 6665} {e 6662} {a 5990} {o 4438} {r 4158} {i 3759} {l 3371} {t 3295} {n 2952} {u 2511} {d 2453} {y 2074} {c 2028} {p 2019} {m 1976} {h 1760} {g 1644} {b 1627} {k 1505} {f 1115} {w 1039} {v 694} {z 434} {j 291} {x 288} {q 112}]
That meas a possible good opener can be AROSE
.
Update 15.01.2022
Someone told me that Wordle are using two list. The first list for the Wordle itself and the second list for possible words. I made the mistake and combined both lists in the last result.
I tried it again with the list for the game and the result is slightly different:
[{e 1233} {a 979} {r 899} {o 754} {t 729} {l 719} {i 671} {s 669} {n 575} {c 477} {u 467} {y 425} {d 393} {h 389} {p 367} {m 316} {g 311} {b 281} {f 230} {k 210} {w 195} {v 153} {z 40} {x 37} {q 29} {j 27}]
e,a,r,o, and t
are the most used letters. I don’t know a word with this letters so I think I will stay with AROSE
as an opener.