Skip to content

Commit

Permalink
drastically speed up permutation finder
Browse files Browse the repository at this point in the history
  • Loading branch information
gwstaten committed Jul 15, 2022
1 parent a5f9f35 commit 7814d6a
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void permute(std::vector<std::string> wordSet, std::vector<std::string> validGue
bool done = !validGuessesPossible.size();
while(!done)
{
unsigned int toIncrement = state.size()-1;
auto tempLetterPos = letterPos;
auto tempFreeLetters = freeLetters;
bool good = true;
Expand All @@ -106,6 +107,7 @@ void permute(std::vector<std::string> wordSet, std::vector<std::string> validGue
else
{
good = false;
toIncrement = i;
}
}
else
Expand Down Expand Up @@ -201,28 +203,35 @@ void permute(std::vector<std::string> wordSet, std::vector<std::string> validGue
anyFound = true;
}
}
state[state.size()-1]++;
state[toIncrement]++;
if(state.size() > 1)
{
if(state[state.size()-1] == validGuessesPossible.size())
if(state[toIncrement] == validGuessesPossible.size())
{
bool stillCarrying = true;
unsigned int on = state.size();
for(unsigned int i = state.size()-2; i >= 0 && stillCarrying; i--)
if(toIncrement == 0)
{
on = i;
state[i]++;
state[i + 1] = 0;
stillCarrying = (state[i] == validGuessesPossible.size() || state[i] + (state.size() - i - 1) >= validGuessesPossible.size());
if(stillCarrying && i == 0)
{
done = true;
stillCarrying = false;
}
done = true;
}
for(unsigned int j = on + 1; j < state.size(); j++)
else
{
state[j] = state[j - 1] + 1;
bool stillCarrying = true;
unsigned int on = state.size();
for(unsigned int i = toIncrement - 1; i >= 0 && stillCarrying; i--)
{
on = i;
state[i]++;
state[i + 1] = 0;
stillCarrying = (state[i] == validGuessesPossible.size() || state[i] + (state.size() - i - 1) >= validGuessesPossible.size());
if(stillCarrying && i == 0)
{
done = true;
stillCarrying = false;
}
}
for(unsigned int j = on + 1; j < state.size(); j++)
{
state[j] = state[j - 1] + 1;
}
}
}
}
Expand Down

0 comments on commit 7814d6a

Please sign in to comment.