int tileCount = [tileString length];
NSMutableArray *tiles = [NSMutableArray arrayWithCapacity:tileCount - 1];
-
for (int i = 0; i < tileCount; i++)
{
[tiles addObject:[tileString substringWithRange:NSMakeRange(i, 1)]];
}
+ // create character sets from the tiles
NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:tileString];
NSCharacterSet *charsetInverted = [charset invertedSet];
+ // iterate over the dictionary to build our word list
for (NSString *word in dictionary)
{
+ // word is larger than the number of tiles we have, remove
if ([word length] > tileCount)
{
continue;
}
- if ([word rangeOfCharacterFromSet:charsetInverted].location == NSNotFound)
+ // if the word contains characters we don't have, then remove it
+ if ([word rangeOfCharacterFromSet:charsetInverted].location != NSNotFound)
{
- [wordlist addObject:[[Word alloc] initWithWord:word]];
+ continue;
}
+
+ [wordlist addObject:[[Word alloc] initWithWord:word]];
}
// resort