Skip to content

Instantly share code, notes, and snippets.

@myshkin5
Last active July 14, 2022 18:55
Show Gist options
  • Save myshkin5/c2dc13666b7349bd191ac3de74bddf82 to your computer and use it in GitHub Desktop.
Save myshkin5/c2dc13666b7349bd191ac3de74bddf82 to your computer and use it in GitHub Desktop.
Best starting words for https://duotrigordle.com
package main
import (
"bufio"
"log"
"os"
"strings"
)
type letterStatus int
const (
unknown letterStatus = iota
yellow
green = 4
)
type word struct {
theWord string
letterStatuses [5]letterStatus
score int
}
type results struct {
work [4]int
score int
}
func main() {
words, err := readWords()
if err != nil {
log.Panic("couldn't open file", err)
}
workChan := make(chan [4]int)
resultsChan := make(chan results)
for n := 0; n < 8; n++ {
go func() {
for work := range workChan {
newWords := make([]word, len(words))
copy(newWords, words)
checkWord(newWords, words[work[0]].theWord)
checkWord(newWords, words[work[1]].theWord)
checkWord(newWords, words[work[2]].theWord)
checkWord(newWords, words[work[3]].theWord)
resultsChan <- results{
work: work,
score: total(newWords),
}
}
}()
}
doneWork := map[[4]int]struct{}{}
go func() {
for a := 0; a < len(words); a++ {
for b := a + 1; b < len(words); b++ {
for c := b + 1; c < len(words); c++ {
for d := c + 1; d < len(words); d++ {
work := [4]int{a, b, c, d}
if _, ok := doneWork[work]; ok {
continue
}
doneWork[work] = struct{}{}
workChan <- work
}
}
}
}
close(workChan)
}()
best := 0
for res := range resultsChan {
if res.score > best {
pctDone := float32(res.work[0]) / float32(len(words)) * 100.0
log.Printf("Best: %d %s, %s, %s, %s %0.0f%% complete",
res.score,
words[res.work[0]].theWord,
words[res.work[1]].theWord,
words[res.work[2]].theWord,
words[res.work[3]].theWord,
pctDone)
best = res.score
}
}
}
func readWords() ([]word, error) {
f, err := os.Open("/home/dschultz/wordle-ubuntu.txt")
if err != nil {
log.Panic("couldn't open file", err)
}
defer func() {
err := f.Close()
if err != nil {
log.Panic("error closing file", err)
}
}()
scanner := bufio.NewScanner(f)
var words []word
for scanner.Scan() {
words = append(words, word{theWord: scanner.Text()})
}
return words, scanner.Err()
}
func total(words []word) int {
t := 0
for _, w := range words {
t += w.score
}
return t
}
func checkWord(words []word, w string) {
for n := range words {
score := 0
for l := 0; l < 5; l++ {
if words[n].theWord[l] == w[l] && words[n].letterStatuses[l] < green {
words[n].letterStatuses[l] = green
}
if strings.Contains(words[n].theWord, string(w[l])) && words[n].letterStatuses[l] < yellow {
words[n].letterStatuses[l] = yellow
}
score += int(words[n].letterStatuses[l])
}
words[n].score = score
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment