Hey Ratboy...here's a little snippet of Java code (apparently we gotta represent!) that would work for your letter matching thing. It's basically a function that takes in a sorted array, and produces every single permutation of it while it still has one. It keeps testing hasNext() for the while loop condition and if it returns true and enters the loop, we call next to get the next "word". Then each "word" would have to be checked against a dictionary. So here's the permutation code...
I had to write a program a few semesters ago that solved crypt arithmetic problems (if you don't know what that is, check it out here ), so it had to make all permutations of a set of letters and another that played boggle (so it had to check words against a dictionary..and recursively search the board to see if it exists) so I just kinda borrowed from both.Code:boolean hasNext()
{return hasAnother;} //where hasAnother is just a boolean
Object next()
{
hasAnother = nextPermutation(tempArray);
return ""; //yeah so it's sloppy code (real one is all static too)...sue me
} // it was only written to play word whomp!
boolean nextPermutation (char[] a)
{
if (a.length <= 1)
{return false;}
int i = a.length - 1;
while (true)
{
int j = i--;
if (a[i] < a[j])
{
int k = a.length;
while (!(a[i] < a[--k])) {}
swap(a, i, k);
reverse(a, j);
return true;
}
if (i == 0)
{
reverse(a, 0);
return false;
}
}
}
void reverse (char[] a, int i)
{
int j = a.length - 1;
while (i < j)
{swap(a, i++, j--);}
}
void swap (char[] a, int i, int j)
{
char tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
Interestingly enough, I have already written something very similar to what you're describing several months ago. My dad really likes playing this game called "Word Whomp" where they jumble up 6 letters and you have to find all the valid words of length 3, 4, 5, or 6...so I just wrote a program to do it for me! :D It's specifically designed for those length words though and won't work for more than that. If you're interested, all necessary files can be found here. The above methods are used in it (and Words.java contains the main method used to run everything).
