Validation is now faster
This commit is contained in:
parent
e4d73dbde1
commit
090e1e6ffe
1 changed files with 8 additions and 9 deletions
17
validate.hpp
17
validate.hpp
|
@ -8,30 +8,29 @@ using std::to_string;
|
||||||
|
|
||||||
|
|
||||||
vector<int> validate(vector<int> sequence, vector<int> guess) {
|
vector<int> validate(vector<int> sequence, vector<int> guess) {
|
||||||
int S = sequence.size();
|
int N = sequence.size();
|
||||||
|
|
||||||
// Return values
|
// Return values
|
||||||
int r_correct = 0;
|
int r_correct = 0;
|
||||||
int r_somewhere = 0;
|
int r_somewhere = 0;
|
||||||
|
|
||||||
// Find and remove correct values
|
// Find and remove correct values
|
||||||
for(int i = 0; i < S; i++) {
|
for(int i = 0; i < N; i++) {
|
||||||
if(sequence[i] == guess[i]) {
|
if(sequence[i] == guess[i]) {
|
||||||
r_correct++;
|
r_correct++;
|
||||||
sequence.erase(sequence.begin()+i);
|
sequence[i] = -1;
|
||||||
guess.erase(guess.begin()+i);
|
guess[i] = -1;
|
||||||
i--;
|
|
||||||
S--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find values that are there somewhere
|
// Find values that are there somewhere
|
||||||
for(int col : guess) {
|
for(int col : guess) {
|
||||||
for(int i = 0; i < S; i++) {
|
if(col == -1)
|
||||||
|
continue;
|
||||||
|
for(int i = 0; i < N; i++) {
|
||||||
if(sequence[i] == col) {
|
if(sequence[i] == col) {
|
||||||
r_somewhere++;
|
r_somewhere++;
|
||||||
sequence.erase(sequence.begin()+i);
|
sequence[i] = -1;
|
||||||
S--;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue