Second Challenge


I am a bit confused on the second challenge. Two files are mentioned here, but the words file seems to contain all of the items that we need to do this challenge (the words plus all of the name), so I am trying to find out what I am missing – I see most other solutions to this challenge loading both files and comparing them. Why not just load the single file that contains everything, go through it word by word and see where there is a match? Using this approach, this code seems to solve the challenge.

[code]#import <Foundation/Foundation.h>

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

@autoreleasepool {
    // Load Words & Names file
    NSString *wordString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
    // Add all names and words to array
    NSArray *words = [wordString componentsSeparatedByString:@"\n"];
    //Count number of items in Array
    NSUInteger wordCount = [words count];
    //For every word in array, check to see if the next item on the list matches the current item.  Stop at second to last item
    for (int i=0; i < wordCount-1; i++){
        //If the current word and the next word match, output them both.
        if([ [words objectAtIndex:i] caseInsensitiveCompare:[words objectAtIndex:(i+1)] ] == NSOrderedSame)
            NSLog(@"%@ and %@ are the same!", [words objectAtIndex:i], [words objectAtIndex:(i+1)]);    
return 0;