I’d greatly appreciate help with that algorithm/pseudo code.
Basically I’m looking for words with a particular pattern (doesn’t matter what). I have a special function to determine it, which returns 1 if the word fulfills the requirements.
When it does, the second word after that should be omitted and not saved in the output.
I had no problem with that, when the “chosen” words are separated by one “not chosen” word.
The problem is – what to do when the “chosen” ones appear one after the other ?
I’ve prepared such a pseudo code to clarify the situation a bit. But unfortunately it doesn’t work for all the combinations of “chosen” and “not chosen”.
I introduced three counters/variables, helping me to discover the position I’m currently at.
Following pseudo code isn’t in logical order!
if (counter == 2 || in_a_row >= 3) {
erase = 1;
counter--;
yes = 0;
if (!chosen)
counter = 0;
}
if (chosen) {
counter++;
yes = 1;
in_a_row++;
} else {
if (yes = 1) /* yes - is used when the preceeding word is chosen and the next is not chosen, in order to keep track of the counter */
counter++;
}
if (in_a_row == 5)
in_a_row = 4; /* just to make sure that counter doesn't go too high */
if (erase == 1)
/*erasing procedure*/
If You have a simpler idea, or see a mistake in that one, PLEASE help me.
Trying to work that out for 8 hours…
Pardon me for not using pseudo-code, instead I used actual code. I’m hoping I now understand the problem well enough that my belief that it doesn’t seem very complicated, is accurate.
With this input:
I got this output:
I just used a simple comparison, not actual regular expressions. I only wanted to illustrate the algorithm. Does the output conform to the requirements?