DEV Community

Cover image for How I found a good opener for Wordle
manuel
manuel

Posted on

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("panic")
    }
    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)
}

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]
}

Enter fullscreen mode Exit fullscreen mode

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".
I checked this on Wordle and yeah, it's a accepted word :)

I checked this against the last 9 days and got following matches:

200: 3
201: 1
202: 0
203: 2
204: 2
205: 2
206: 2
207: 2
208: 2
Enter fullscreen mode Exit fullscreen mode

Now, the next letters are o,s,l,n, and c. A word for this combination of letters can be "CLONS". I checked this on Wordle and it's a accepted word too. I got following improvements against the last 9 days:

200: 3 => 3
201: 1 => 3
202: 0 => 2
203: 2 => 4
204: 2 => 3
205: 2 => 2
206: 2 => 3
207: 2 => 3
208: 2 => 2
Enter fullscreen mode Exit fullscreen mode

I wrote this really quickly, hope I haven't made many mistakes.

Update

I got the Wordlist from Wordle itself an 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 means a got opener is arose followed by until

What are your words to open the game?

Top comments (5)

Collapse
 
kjlubick profile image
Kevin Lubick

I believe Wordle uses two lists of words - one list contains that can be used for the game (i.e. "common" words), and one list contains all valid words that it accepts. Consider focusing on the smaller list (2315 words when I looked) so that you are not trying to match against words that do not exist. It might not change your analysis too much, but could be worth investigation.

Collapse
 
mnlwldr profile image
manuel

Thank you Kevin, that's a good point. I combined both list. Maybe I try it again with the correct list for Wordle.

Collapse
 
mnlwldr profile image
manuel

I checked the Wordlist from Wordle. The result:

[{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.

Collapse
 
arinbasu profile image
Arindam Basu

You started with a known solution to find out the best possible five letter word to start with. While this may work with a specific word, the challenge is to identify which combination of letters that will also be a valid word in their 'dictionary' that can lead to matching the word in question. Unfortunately that solution is difficult to converge as it seems that they have a pool of n number of words, i.e., n*5 number of non-ransom assortment of letters presented non-random order. Your code has not provided the solution to the best starting word or if it did can you please explain? Reading the code it was not clear. If you can please annotate that'd be great.
Some people suggest NLP to start with most frequent words in English language and their assortment of letters ; while this may be useful the approach is likely to be wrong because in this localised solution, we are testing out only a fixed set of character solutions.
If you want, you can cheat the system by first downloading their sets of words and letters from the site, and then reconstructing the words etc. While this may match some solutions, there is no guarantee that will give you the best starting prior.
Tricky stuff

Collapse
 
mnlwldr profile image
manuel

Thank you for the comment Arindam, i just wanted to look at the dictionary which 5 letters are most used. I extracted the Wordlist from the Wordle JavaScript and the most used letters are "s,e,a,o,r". This just means, that "AROSE" can be a good opener.