Skip to content

Commit 9bde8a4

Browse files
authored
Merge pull request #16 from UBC-MDS/get_n_guesses
Get n guesses
2 parents 31edf98 + 6993696 commit 9bde8a4

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/wordguess/_internals.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
minidict = [
2+
"apple", "baker", "chair", "delta", "eagle", "frame", "grape", "house", "ivory", "joker",
3+
"knife", "lemon", "mango", "night", "ocean", "piano", "queen", "river", "stone", "tiger",
4+
"unity", "value", "wheat", "mount", "young", "zebra", "alert", "brave", "crane", "dream",
5+
"enemy", "field", "giant", "heart", "input", "judge", "about", "layer", "metal", "north",
6+
"olive", "pride", "quest", "rough", "sharp", "table", "under", "visit", "world", "yield",
7+
"aside", "blush", "cloud", "dwarf", "empty", "fresh", "glide", "honor", "inner", "light",
8+
"march", "noble", "other", "plain", "quiet", "ratio", "smart", "trust", "upper", "shout",
9+
"woman", "years", "angle", "beach", "crown", "drive", "exact", "flame", "green", "habit",
10+
"index", "logic", "money", "nurse", "offer", "patch", "quick", "royal", "scale", "thick",
11+
"urban", "video", "worth", "extra", "basic", "clean", "focus", "happy", "ideal", "smile"
12+
]

src/wordguess/get_n_guesses.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from ._internals import minidict
2+
3+
def get_n_guesses(result_hist: dict, n: int = None, corpus: list = minidict) -> list:
4+
"""
5+
Return all possible target words consistent with the result history.
6+
7+
This function filters the given corpus of allowed words using the information
8+
contained in a result history. Each entry in the result history consists of
9+
a guessed word and its corresponding result string, where:
10+
- '0' indicates the letter is not present in the target word,
11+
- '1' indicates the letter is present but in the wrong position, and
12+
- '2' indicates the letter is correct and in the correct position.
13+
14+
Words in the corpus that violate any of the constraints implied by the result
15+
history are eliminated and the remaining words are considered to be possible
16+
valid guesses. If the parameter n is provided, n random words from the valid
17+
guesses are returned. If n is None, all valid guesses are returned.
18+
19+
Parameters:
20+
result_hist (dict): A dictionary mapping previously guessed words to their
21+
corresponding result strings composed of '0', '1', and '2'.
22+
n (int): The number of valid guesses to return. If None, all valid guesses
23+
are returned.
24+
corpus (list): A list of all allowed words to consider as possible targets.
25+
26+
Returns:
27+
list: A list of words from the corpus that are consistent with the result history.
28+
29+
Example:
30+
>>> result_hist = {"crane": "01200", "sloth": "10020"}
31+
>>> get_n_guesses(result_hist, corpus=corpus)
32+
Output: ['about', 'shout', 'mount']
33+
34+
>>> get_n_guesses(result_hist, n=2, corpus=corpus)
35+
Output: ['shout', 'mount']
36+
"""
37+
# TODO: write checks for input
38+
# TODO: write the function body
39+
return corpus

0 commit comments

Comments
 (0)