Here is my solution


#1

[code]//
// main.m
// properNames
//
// Created by Peter Gosling on 8/9/13.
// Copyright © 2013 Peter Gosling. All rights reserved.
//

#import <Foundation/Foundation.h>

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

@autoreleasepool {
    
    //Read a file as a huge string (ignoring the possibility of an error)
    NSString *nameString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" encoding:NSUTF8StringEncoding error:NULL];
    
    NSString *wordString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
    
    //Break it into an array
    NSArray *names = [nameString componentsSeparatedByString:@"\n"];
    NSArray *words = [wordString componentsSeparatedByString:@"\n"];

    //Loop through the list n
    for (NSString *n in names) {
        //Loop throught the list c
        for (NSString *c in words) {
            //Compares the results and determine if one is equal
            if ([n isEqualToString:c]) {
                NSLog(@"%@ and %@ are the same!", c, n);
            }
        }
    }[/code]

This is my solution. This one was more difficult than the previous challenges. I haven’t used the “isEqualToString” method before and had to come to the forums to figure out why my code with the given “caseInsensitiveCompare” method wasn’t working. Frustrating.


#2

Doesn’t this just print the names too?

IE;
Al and Al are the same!
Al and al are the same!
Art and Art are the same!
Art and art are the same!

My solution is similar to yours. I have the issue I mentioned above. I can’t figure out a way to omit the proper names from duplicating. I’ll put the loop section of my code below.

// Go through the name array one string at a time for (NSString *n in names) { // Go through the words array one string at a time for (NSString *w in words) { // Is the name a word also? if ([n caseInsensitiveCompare:w] == NSOrderedSame) { NSLog(@"%@ & %@", n, w); } } }