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) {
|
||||
int S = sequence.size();
|
||||
int N = sequence.size();
|
||||
|
||||
// Return values
|
||||
int r_correct = 0;
|
||||
int r_somewhere = 0;
|
||||
|
||||
// Find and remove correct values
|
||||
for(int i = 0; i < S; i++) {
|
||||
for(int i = 0; i < N; i++) {
|
||||
if(sequence[i] == guess[i]) {
|
||||
r_correct++;
|
||||
sequence.erase(sequence.begin()+i);
|
||||
guess.erase(guess.begin()+i);
|
||||
i--;
|
||||
S--;
|
||||
sequence[i] = -1;
|
||||
guess[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Find values that are there somewhere
|
||||
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) {
|
||||
r_somewhere++;
|
||||
sequence.erase(sequence.begin()+i);
|
||||
S--;
|
||||
sequence[i] = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue