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