My solution to challenge #2


#1

Below is my solution to the second challenge. The only question I have, is how do I get rid of the last match where they are blank?

[Edit: I figured it out, by adding an if (![n isEqualToString:w]) after the second for loop.]

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

int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames"
encoding:NSUTF8StringEncoding
error:NULL];
NSString *wordString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words"
encoding:NSUTF8StringEncoding
error:NULL];

    NSArray *names = [nameString componentsSeparatedByString:@"\n"];
    NSArray *words = [wordString componentsSeparatedByString:@"\n"];
    
    int i = 0;
    for (NSString *w in words) {
        for (NSString *n in names) {
            if (![n isEqualToString:w]){
                if ([n isEqualToString:[w capitalizedString]] &&
                    [w isEqualToString:[w lowercaseString]]) {
                            i++;
                            NSLog(@"%d: %@/%@", i, w, n);
                }
            }
        }
    }
 }
return 0;

}
[/code]

It might not be the fastest, but using what we know, it does seem to work.