Challenge 2: words and propernames files


Why does the words file on my computer contain all the names? And some are listed twice, “Woody” and then “woody”. Yvonne is a word? And so is Z? I’m matching 34368 entries:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])

    @autoreleasepool {
        //find names that match proper nouns /usr/shar/dict/words
        NSString *namesString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
        NSArray *names = [namesString componentsSeparatedByString:@"\n"];
        NSString *wordsString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words"
        NSArray *words = [wordsString componentsSeparatedByString:@"\n"];
        int numberFound;
        for(NSString *aName in names){
            for(NSString *aWord in words){
                NSRange match = [aName rangeOfString: aWord options:NSCaseInsensitiveSearch ];

                //this will match sub strings so also compare string length
                if( match.location != NSNotFound && aName.length == aWord.length){
                    NSLog(@"Match! Word: %@ Name: %@",aWord,aName);

        NSLog(@"Name count: %i", (int)names.count);
        NSLog(@"Total found: %i",numberFound);
    return 0;

sample of words file data:


Relax, they are all words! Yes, Z too is a word.


I didn’t think Yvonne was a word, it looks like every single name is a word, every name I have searched for manually in my words file is in there. Do you see a problem with my algorithm? I got 34368 matches so I did something wrong. I thought it should only match about 230ish?



I found ~300 words. Don’t forget to search for the lowercase version of the names in the word list.