Bulls and cows: Difference between revisions
→{{header|C++}}: oops, forgot to check for duplicates in the guess
m (→{{header|C++}}: removed unused variable) |
(→{{header|C++}}: oops, forgot to check for duplicates in the guess) |
||
Line 167:
#include <algorithm>
#include <cstdlib>
bool contains_duplicates(std::string s)
{
std::sort(s.begin(), s.end());
return std::adjacent_find(s.begin(), s.end()) != s.end();
}
void game()
Line 181 ⟶ 187:
{
if (guess.length() != selection_length
|| guess.find_first_not_of(symbols) != std::string::npos
|| contains_duplicates(s))
{
std::cout << guess << " is not a valid guess!";
|