Select Random Word: Detecting when two words share a letter

Hi,

I’ve found a first random word and stored it in “selected1”. Then, for the quantum version, I want to find a second random word, which has no letters in common with “selected1”. To this purpose, I want to create a list of allowed words. Hence, for each word in the file I check whether it shares any character with “selected1”. I do this as follows:

// read word3
    for (int i=0; i < k; i++) {
        for (int j=0; j < k; j++) {
            if (word3[i] == selected1[j]) {
                // take a note that this word is not allowed
            }
        }
    }

This works in some minimal artifical example. However, in the project, words somehow sneak into the list which share a letter with “selected1”. I’m not sure why.

With the code you check

\exists 0\leq i, j <k. \mathrm{word3}_i=\mathrm{selected1}_j

which seems to be what you want to do.
It now depends on what you do with the information if you know that they share a character or not.
It might also be the case that you store the words incorrectly.
Take care when memory is overwritten and freed.
Especially, take a look if the content of word3 still exists in its intended form where you use it.

1 Like

Thanks for your reply. I realized that I was not searching the list of allowed words but the original dictionary, i.e. all words. However, now, I tried to properly store the allowed words but I’m facing another issue. I presume I will create a new topic.