filter_words: Filter a list of words based upon letter constraints

Description Usage Arguments Value Examples

View source: R/wordle-helper.R

Description

Filter a list of words based upon letter constraints

Usage

1
2
3
4
5
6
7
filter_words(
  words,
  exact = ".....",
  wrong_spot = c("", "", "", "", ""),
  min_count = c(),
  known_count = c()
)

Arguments

words

character vector of candidate words

exact

single string representing known characters in the word, with '.' used to indicate the letter at this position is unknown. E.g. For a 5 letter word if the 3rd and 4th letters are known to be 'a' and 'c', but all other letters are unknown, then exact = "..ac."

wrong_spot

a character vector the same length as the number of letters in the target word. Each string in this vector represents all letters which are known to be part of the word, but in the wrong spot. E.g. if 'a' has been attempted as the first character, and it exists in the word, but worlde claims it is not yet in the correct position, then wrong_spot = c('a', '', '', '', '')

min_count

named character vector giving letters and their minimum counts. E.g. If it is known that there are at least 2 'o's in the word: min_count = c(o = 2)

known_count

named character vector giving letters and their known total counts. This can be used to exclude all words with a particular letter by setting the count for that letter to zero.

Value

character vector of words filtered from the original words which match the constraints given.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# Searching for a word:
#
# with 9 letters
# starting with `p`
# containing `v` and `z` somewhere, but not as the first letter
# containing only one `z`
# without an `a` or an `o` in it
#
words <- readLines("/usr/share/dict/words")

filter_words(
  words            = words,
  exact            = "p........",
  wrong_spot       = c("vz", "", "", "", "", "", "", "", ""),
  min_count        = c(v = 1),
  known_count      = c(z = 1, a = 0, o = 0)
)

## End(Not run)

ylmazkanat/world.github.io documentation built on Jan. 24, 2022, 12:07 a.m.