51 lines
1,006 B
C++
51 lines
1,006 B
C++
#pragma once
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
using std::vector;
|
|
using std::string;
|
|
using std::to_string;
|
|
|
|
vector<int> validate(vector<int> sequence, vector<int> guess) {
|
|
int S = sequence.size();
|
|
|
|
// Return values
|
|
int r_correct = 0;
|
|
int r_somewhere = 0;
|
|
|
|
// Find and remove correct values
|
|
for(int i = 0; i < S; i++) {
|
|
if(sequence[i] == guess[i]) {
|
|
r_correct++;
|
|
sequence.erase(sequence.begin()+i);
|
|
guess.erase(guess.begin()+i);
|
|
i--;
|
|
S--;
|
|
}
|
|
}
|
|
|
|
// Find values that are there somewhere
|
|
for(int col : guess) {
|
|
for(int i = 0; i < S; i++) {
|
|
if(sequence[i] == col) {
|
|
r_somewhere++;
|
|
sequence.erase(sequence.begin()+i);
|
|
S--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return {r_somewhere, r_correct};
|
|
}
|
|
|
|
string format_response(vector<int> response) {
|
|
return to_string(response[0]) + " somewhere / " + to_string(response[1]) + "on the right spot\n";
|
|
}
|
|
string format_guess(vector<int> guess) {
|
|
string r = "";
|
|
for(int col : guess)
|
|
r += to_string(col) + " ";
|
|
r += "\n";
|
|
return r;
|
|
}
|