DEV Community

manuel
manuel

Posted on • Originally published at defer.cc on

2 2

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

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay