diff --git a/wordle.cc b/wordle.cc index 4004f81..d588925 100644 --- a/wordle.cc +++ b/wordle.cc @@ -41,6 +41,32 @@ void usage(char *); +std::vector yellow_search(std::string invalid, std::string yellow) { + std::vector candidates; + for (std::vector::size_type i = 0; i < wordv.size(); i++) { + std::string word(wordv[i]); + bool valid = false; + for (std::string::size_type j = 0; j < yellow.length(); j++) { + if (word.find(yellow[j]) == std::string::npos) { + valid = false; + break; + } else { + valid = true; + } + } + for (int j = 0; j < 5; j++) { + if (invalid.find(word[j]) != std::string::npos) { + valid = false; + break; + } + } + if (valid) { + candidates.push_back(word); + } + } + return candidates; +} + std::vector green_search(std::string invalid, std::string yellow, std::string green) { std::vector candidates; @@ -119,6 +145,8 @@ int main(int argc, char **argv) { } if (green != "?????") { candidates = green_search(invalid, yellow, green); + } else { + candidates = yellow_search(invalid, yellow); } std::for_each(candidates.begin(), candidates.end(), [](std::string n) { std::cout << n << " "; });