wordgame

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 1 Imported by: 0

README

wordgame GoDoc

Package wordgame provides a dictionary search for word games.

Given a dictionary and list of required characteds, the search returns list of matching words which include all the required characters.

Usage

package wordgame_test

import (
	"fmt"

	"github.com/aquilax/wordgame"
)

func ExampleWordList_Filter() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
	})
	result := wl.Filter(wordgame.GivenWithExtra("co", 0))
	fmt.Printf("%+v", result)
	// Output: [cow brocolly]
}

func ExampleWordList_Filter_Len() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
		"coworker",
		"comb",
	})
	result := wl.Filter(wordgame.GivenWithExtra("co", 4))
	fmt.Printf("%+v", result)
	// Output: [comb]
}

func ExampleWordList_FilterConcurrent() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
	})
	result := wl.FilterConcurrent(wordgame.GivenWithExtra("co", 0), 2)
	fmt.Printf("%+v", result)
	// Output: [cow brocolly]
}

func ExampleWordList_FilterConcurrent_OnlyGiven() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
	})
	result := wl.FilterConcurrent(wordgame.OnlyGiven("cowz", 0), 2)
	fmt.Printf("%+v", result)
	// Output: [cow]
}

Documentation

Overview

Package wordgame provides a dictionary search for word games. Given a dictionary and list of required characteds, the search returns list of matching words which include all the required characters.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FilterFunc

type FilterFunc func([]rune) bool

FilterFunc filtering function

func GivenWithExtra

func GivenWithExtra(letters string, l int) FilterFunc

GivenWithExtra returns function matching all given characters plus any other character

func OnlyGiven

func OnlyGiven(letters string, l int) FilterFunc

OnlyGiven returns function matching only the given characters

type WordList

type WordList [][]rune

WordList holds the dictionary

func New

func New() *WordList

New creates new empty dictionary

func NewFromStrings

func NewFromStrings(sl []string) *WordList

NewFromStrings creates new dictionary and populates it with words

func (WordList) Filter

func (wl WordList) Filter(ff FilterFunc) []string

Filter searches for matches by applying the filter function

Example
package main

import (
	"fmt"

	"github.com/aquilax/wordgame"
)

func main() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
	})
	result := wl.Filter(wordgame.GivenWithExtra("co", 0))
	fmt.Printf("%+v", result)
}
Output:

[cow brocolly]

func (WordList) FilterConcurrent

func (wl WordList) FilterConcurrent(ff FilterFunc, numWorkers int) []string

FilterConcurrent searches for matches by applying the filter function using pool of workers

Example
package main

import (
	"fmt"

	"github.com/aquilax/wordgame"
)

func main() {
	wl := wordgame.NewFromStrings([]string{
		"cow",
		"chicken",
		"horse",
		"brocolly",
	})
	result := wl.FilterConcurrent(wordgame.GivenWithExtra("co", 0), 2)
	fmt.Printf("%+v", result)
}
Output:

[cow brocolly]

Jump to

Keyboard shortcuts

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