I would generalize this problem the following way (if I understood your problem right):
Create a function
bool nextVariant(const &prev_x, &new_x) that is going to generate a new candidate
new_x based on the previously explored one
prev_x. Then you can organize your code as follows (I made a sketch of a pseudocode using C-style syntaxis)
CandidateType x(0); //initialize the starting candidate (possibility)
performAnalysis(x); //do whatever you want with the candidate
CandidateType prev_x = x; //maybe you need to save it, maybe not....
bool isThereNext = nextVariant(prev_x,x);
bool nextVariant(const CandidateType& prev_x, CandidateType& x)
//your logic to create x from prev_x. (assign x)
else return false;
CandidateType is the "type" of your "possibility". You will define it based on your problem, whether it is an N-spot with 2-positions, or something more complicated.
With that, you moved the complication towards generating a new possibility from a previous one, which is usually an easy thing to do. Since I don't know exactly what could be the possible intent of generating those "candidates", I might have introduced certain inefficiencies that could be avoided.