DEV Community

manuel
manuel

Posted on • Originally published at defer.cc on

Wordle solver

#go

Just for fun tool to search in the Wordle wordlist.

Usage

Usage of ./wordle-solver:
  -except string
        Characters to except (e.g.: "aeou")
  -match string
        The string to match (placeholder: .) (default ".....")
  -wordlist string
        Wordlist to use (default "Wordlist")

Enter fullscreen mode Exit fullscreen mode

Example Todays Worlde is “BRAND” for example and we started with “IRATE”.

wordle-solver -match ".ra.." -except "ite"

You got a list of 27 possible words.

Wordle solver on GitHub

package main

import (
    "bufio"
    "flag"
    "fmt"
    "log"
    "os"
    "regexp"
)

func main() {
    wordlistFlag := flag.String("wordlist", "Wordlist", "Wordlist to use")
    matchFlag := flag.String("match", ".....", "The string to match (placeholder: .)")
    exceptFlag := flag.String("except", "", "Characters to except (e.g.: \"aeou\")")
    flag.Parse()

    file, err := os.Open(*wordlistFlag)
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    scanner := bufio.NewScanner(file)
    for scanner.Scan() {
        match, _ := regexp.MatchString(*matchFlag, scanner.Text())
        except, _ := regexp.MatchString(fmt.Sprintf(`[%s]`, *exceptFlag), scanner.Text())
        if match && !except {
            fmt.Println(scanner.Text())
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)