How I found a good opener for Wordle
Tags: go, programming, watercooler, showdev
Published: 2022-01-13 18:48:30

---
title: How I found a good opener for Wordle
published: true
description: How I found a good opener for Wordle
tags: Go, programming, watercooler, showdev
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kg42ecpk1hpflp5pxcqm.jpeg
---

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)

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

```

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
```

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
```

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?