I implemented a computerized version of a game similar to the board game Boggle. Given a jumble of letters find as many words as possible. Suppose we have the jumbled letters “sldfie” then my C++ program outputs:

Now suppose the scrambled letters are “nifrsmo”:

The program uses permutations and power sets. All permutations of the set of three numbers 1, 2, and 3 are:
123 132 213 231 312 321
The total number of permutations of n objects is n! where n! = n * (n – 1) * … * 2 * 1. So we have 3! = 3 * 2 * 1 = 6 and 4! = 4 * 3 * 2 * 1 = 24.
A power set of three objects can generated by using the binary representation of all binary numbers 0 to 2 * 2 * 2 – 1 = 8 – 1 = 7.
0 = 000, 1 = 001, 2 = 010, 3 = 011, 4 = 100, 5 = 101, 6 = 110, and 7 = 111
My main C++ function in the implementation is as follows:
vector<string> PowerSet(char cstr[], int len)
{
vector<int> index;
vector<string> match;
for (long ps = 0; ps <= pow(2, len); ps++)
{
string str = ConvertBase2(cstr, ps, len);
int psf = 1;
for (int i = 2; i <= len; i++)
psf *= i;
for (int i = 0; i < psf; i++)
{
if (binary_search(dictWords.begin(), dictWords.end(), str))
{
if (!binary_search(match.begin(), match.end(), str))
{
match.push_back(str);
sort(match.begin(), match.end());
}
}
next_permutation(str.begin(), str.end());
}
}
return match;
}






















