qordle

package module
v0.3.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2024 License: MIT Imports: 25 Imported by: 0

README

qordle

build codecov Go Report Card

Simple wordle solution suggester

Install

$ brew tap bzimmer/tap
$ brew install qordle

Usage

qordle uses the hits, misses, and a pattern (if known) to suggest words matching the solution. See the complete manual for more features and documentation.

Input

  • Input correctly placed letters as an uppercase
  • Input incorrectly placed letters as a lowercase letter preceded by any symbol (., @)
  • Input misses as lowercase letters

Example

Screenshot

$ qordle suggest -s position -w solutions b.rAin stARt peARl
["chard","award","guard","charm","hoard","wharf","dwarf","quark","ovary"]
$ qordle play --start brain table | jq
{
  "secret": "table",
  "strategy": "frequency",
  "dictionary": 12947,
  "rounds": [
    {
      "dictionary": 118,
      "scores": [
        "~br~ain"
      ],
      "words": [
        "brain"
      ],
      "success": false
    },
    {
      "dictionary": 5,
      "scores": [
        "~br~ain",
        "mAB~es"
      ],
      "words": [
        "brain",
        "mabes"
      ],
      "success": false
    },
    {
      "dictionary": 4,
      "scores": [
        "~br~ain",
        "mAB~es",
        "cABLE"
      ],
      "words": [
        "brain",
        "mabes",
        "cable"
      ],
      "success": false
    },
    {
      "dictionary": 3,
      "scores": [
        "~br~ain",
        "mAB~es",
        "cABLE",
        "fABLE"
      ],
      "words": [
        "brain",
        "mabes",
        "cable",
        "fable"
      ],
      "success": false
    },
    {
      "dictionary": 2,
      "scores": [
        "~br~ain",
        "mAB~es",
        "cABLE",
        "fABLE",
        "gABLE"
      ],
      "words": [
        "brain",
        "mabes",
        "cable",
        "fable",
        "gable"
      ],
      "success": false
    },
    {
      "dictionary": 1,
      "scores": [
        "~br~ain",
        "mAB~es",
        "cABLE",
        "fABLE",
        "gABLE",
        "hABLE"
      ],
      "words": [
        "brain",
        "mabes",
        "cable",
        "fable",
        "gable",
        "hable"
      ],
      "success": false
    },
    {
      "dictionary": 1,
      "scores": [
        "~br~ain",
        "mAB~es",
        "cABLE",
        "fABLE",
        "gABLE",
        "hABLE",
        "TABLE"
      ],
      "words": [
        "brain",
        "mabes",
        "cable",
        "fable",
        "gable",
        "hable",
        "table"
      ],
      "success": true
    }
  ],
  "elapsed": 2
}

Strategies

qordle supports a number of different strategies and those strategies can be chain to build new strategies.

Performance of different strategy compositions for 2000 randomly sampled words

strategy winners total pct
speculate{chain{frequency,position}} 1930 2000 96.5
speculate{chain{frequency,position,bigram}} 1915 2000 95.8
speculate{chain{frequency,elimination}} 1911 2000 95.5
speculate{chain{frequency,bigram}} 1877 2000 93.8
speculate{frequency} 1875 2000 93.8
speculate{elimination} 1868 2000 93.4
speculate{position} 1858 2000 92.9
speculate{bigram} 1663 2000 83.2

Documentation

Overview

Code generated by go generate; DO NOT EDIT.

Index

Constants

View Source
const RuntimeKey = "github.com/bzimmer/qordle#RuntimeKey"

RuntimeKey in app metadata

Variables

View Source
var ErrInvalidFormat = errors.New("invalid pattern format")
View Source
var ErrInvalidLength = errors.New("secret and guess lengths do not match")

Functions

func CommandDigits

func CommandDigits() *cli.Command

func CommandLetterBoxed

func CommandLetterBoxed() *cli.Command

func CommandOrder

func CommandOrder() *cli.Command

func CommandPlay

func CommandPlay() *cli.Command

func CommandRanks

func CommandRanks() *cli.Command

func CommandScore

func CommandScore() *cli.Command

func CommandStrategies

func CommandStrategies() *cli.Command

func CommandSuggest

func CommandSuggest() *cli.Command

func CommandValidate

func CommandValidate() *cli.Command

func CommandVersion

func CommandVersion() *cli.Command

func CommandWordlists

func CommandWordlists() *cli.Command

func NoOp

func NoOp(_ string) bool

func Score

func Score(secret string, guesses ...string) ([]string, error)

Types

type Alpha

type Alpha struct{}

Alpha orders the dictionary alphabetically

func (*Alpha) Apply

func (s *Alpha) Apply(words Dictionary) Dictionary

func (*Alpha) String

func (s *Alpha) String() string

type Bigram

type Bigram struct{}

Bigram sorts the dictionary by the bigram frequency of the word

func (*Bigram) Apply

func (s *Bigram) Apply(words Dictionary) Dictionary

func (*Bigram) String

func (s *Bigram) String() string

type Board

type Board []int

type Box

type Box struct {
	// contains filtered or unexported fields
}

func NewBox

func NewBox(opts ...BoxOption) *Box

func (*Box) Solutions

func (box *Box) Solutions(words []string) <-chan []string

func (*Box) Words

func (box *Box) Words(trie *Trie[any]) []string

type BoxOption

type BoxOption func(*Box)

func WithConcurrent

func WithConcurrent(n int) BoxOption

func WithMaxSolutionLength

func WithMaxSolutionLength(n int) BoxOption

func WithMinWordLength

func WithMinWordLength(n int) BoxOption

func WithSides

func WithSides(sides string) BoxOption

type Candidate

type Candidate struct {
	Board Board      `json:"board"`
	Ops   Operations `json:"ops"`
}

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain chains multiple strategies to sort the wordlist

func (*Chain) Apply

func (s *Chain) Apply(words Dictionary) Dictionary

func (*Chain) String

func (s *Chain) String() string

type Dictionary

type Dictionary []string

func Filter

func Filter(words Dictionary, fns ...FilterFunc) Dictionary

func Read

func Read(name string) (Dictionary, error)

type Digits

type Digits struct{}

func (Digits) Play

func (d Digits) Play(ctx context.Context, board Board, target int) <-chan Candidate

type Elimination

type Elimination struct{}

func (*Elimination) Apply

func (s *Elimination) Apply(words Dictionary) Dictionary

func (*Elimination) String

func (s *Elimination) String() string

type Encoder

type Encoder interface {
	// Encode writes the encoding of v
	Encode(v any) error
}

Encoder encodes a struct to a specific format

type FilterFunc

type FilterFunc func(string) bool

FilterFunc performs a validation on the word

func Guess

func Guess(guesses ...string) (FilterFunc, error)

func IsLower

func IsLower() FilterFunc

func Length

func Length(length int) FilterFunc

type Frequency

type Frequency struct{}

Frequency sorts the wordlist by letter frequency

func (*Frequency) Apply

func (s *Frequency) Apply(words Dictionary) Dictionary

func (*Frequency) String

func (s *Frequency) String() string

type Game

type Game struct {
	// contains filtered or unexported fields
}

func NewGame

func NewGame(opts ...Option) *Game

NewGame creates a new client and applies all provided Options

func (*Game) Play

func (g *Game) Play(secret string) (*Scoreboard, error)

Play the game for the secret

type Grab

type Grab interface {
	Do(*http.Request) (*http.Response, error)
}

type Graph

type Graph map[rune][]string

type Mark

type Mark int

Mark is the state for a letter

const (
	MarkMiss      Mark = 0
	MarkMisplaced Mark = 1
	MarkExact     Mark = 2
)

type Marks

type Marks []Mark

Marks is a slice of marks

func Check

func Check(secret string, guesses ...string) ([]Marks, error)

type Operation

type Operation struct {
	Op  Operator `json:"op"`
	LHS int      `json:"lhs"`
	RHS int      `json:"rhs"`
	Val int      `json:"val"`
}

func (Operation) String

func (o Operation) String() string

type Operations

type Operations []Operation

func (Operations) Hash

func (o Operations) Hash() string

func (Operations) String

func (o Operations) String() string

type Operator

type Operator int
const (
	OpAdd      Operator = 0
	OpMultiply Operator = 1
	OpSubtract Operator = 2
	OpDivide   Operator = 3
)

func (Operator) String

func (o Operator) String() string

type Option

type Option func(*Game)

Option provides a configuration mechanism for a Game

func WithDictionary

func WithDictionary(dictionary Dictionary) Option

WithDictionary is the dictionary to use

func WithRounds

func WithRounds(rounds int) Option

func WithStart

func WithStart(start string) Option

WithStart is the first word to use

func WithStrategy

func WithStrategy(strategy Strategy) Option

WithStrategy is the strategy to use

type Position

type Position struct{}

Position sorts the word list be letter position

func (*Position) Apply

func (s *Position) Apply(words Dictionary) Dictionary

func (*Position) String

func (s *Position) String() string

type Round

type Round struct {
	Dictionary int      `json:"dictionary"`
	Scores     []string `json:"scores"`
	Words      []string `json:"words"`
	Success    bool     `json:"success"`
}

type Rt

type Rt struct {
	// Encoder encodes a struct
	Encoder Encoder
	// Grab for querying http endpoints
	Grab Grab
	// Start time of the execution
	Start time.Time
	// Strategies manages the available strategies
	Strategies Strategies
}

Rt for access to runtime components

func Runtime

func Runtime(c *cli.Context) *Rt

type Scoreboard

type Scoreboard struct {
	Secret     string   `json:"secret"`
	Strategy   string   `json:"strategy"`
	Dictionary int      `json:"dictionary"`
	Rounds     []*Round `json:"rounds"`
	Elapsed    int64    `json:"elapsed"`
}

type Speculate

type Speculate struct {
	// contains filtered or unexported fields
}

Speculate attempts to find a word which eliminates the most letters

func (*Speculate) Apply

func (s *Speculate) Apply(words Dictionary) Dictionary

func (*Speculate) String

func (s *Speculate) String() string

type Strategies

type Strategies interface {
	Strategy(string) (Strategy, error)
	Strategies() []string
}

type Strategy

type Strategy interface {
	String() string
	Apply(Dictionary) Dictionary
}

func NewChain

func NewChain(strategies ...Strategy) Strategy

func NewSpeculator

func NewSpeculator(words Dictionary, strategy Strategy) Strategy

type Trie

type Trie[T any] struct {
	// contains filtered or unexported fields
}

func (*Trie[T]) Add

func (trie *Trie[T]) Add(word string, value T)

func (*Trie[T]) Node

func (trie *Trie[T]) Node(word string) *Trie[T]

func (*Trie[T]) Prefix

func (trie *Trie[T]) Prefix() bool

func (*Trie[T]) Strings

func (trie *Trie[T]) Strings() []string

func (*Trie[T]) Value

func (trie *Trie[T]) Value(prefix string) T

func (*Trie[T]) Word

func (trie *Trie[T]) Word() bool

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL