The program is structured into three main components that work together to solve Wordle puzzles. The first part handles the loading and preparation of the word list. The *read\_candidates* function reads all words from a file and filters out those that are not exactly five letters long. At the same time, the words are converted to lowercase, and duplicates are removed. This ensures that the program starts with a clean list of potential solutions.
The *build_list* function processes user input to create mappings of letters to their respective indices. This function plays a crucial role in interpreting user-provided data about correct and misplaced letters, converting it into a format usable by the filtering logic. By breaking down input strings into index-letter pairs, *build_list* ensures the program can apply precise filtering conditions.
The second part of the program focuses on filtering words based on user input. Three functors are used to handle different types of requirements:
- *wrong\_fn*: Filters out words that contain letters the user has marked as "incorrect".
- *correct\_fn*: Ensures that the remaining words have all the green letters at the correct positions.
- *misplaced\_fn*: Checks that yellow letters are present in the word but not at the specified incorrect positions.
These functors are applied in the *do\_filter* function, which filters the current list of candidates based on the user's criteria. After each step, the number of possible solutions decreases until only one candidate remains, or the user decides to exit.
The third component manages user interaction. The *prompt* function is used to gather input from the user, such as letters that do not appear in the word, green letters with their positions, and yellow letters with their incorrect positions. This input is then used to update the filtering process.
The program is straightforward to use and relies on clear filtering logic. The use of **C++17** and the standard library makes the code efficient and easy to read. A possible improvement could involve better validation of user input to avoid errors.