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"
                                                          encoding:NSUTF8StringEncoding
                                                             error:NULL];
        
        NSArray *names = [namesString componentsSeparatedByString:@"\n"];
        
        NSString *wordsString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words"
                                                          encoding:NSUTF8StringEncoding
                                                             error:NULL];
        
        NSArray *words = [wordsString componentsSeparatedByString:@"\n"];
        
        int numberFound;
        for(NSString *aName in names){
            //NSLog(@"%@",aName);
        
            for(NSString *aWord in words){
                NSRange match = [aName rangeOfString: aWord options:NSCaseInsensitiveSearch ];
                //NSLog(@"%@",aWord);

                //this will match sub strings so also compare string length
                if( match.location != NSNotFound && aName.length == aWord.length){
                    numberFound++;
                    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?

Cheers.

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