Challenge 15 Solution


#1

main.m

[code]//
// main.m
// Challenge 15 NSArray
//
// Created by Bernardo Mondragón Brozon on 07/08/13.
// Copyright © 2013 Bernardo Mondragón Brozon. All rights reserved.
//

#import <Foundation/Foundation.h>

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

@autoreleasepool {
    NSString *properNames = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" encoding:NSUTF8StringEncoding error:NULL];
    NSString *commonNames = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];
    NSArray *p =[properNames componentsSeparatedByString:@"\n"];
    NSArray *c =[commonNames componentsSeparatedByString:@"\n"];
    //Create a list of words
    for (NSString *pw in p) {
        //Create a list for each word
        for (NSString *cw in c) {
            if ([pw caseInsensitiveCompare:cw]==NSOrderedSame) { //Compare them
                if (![pw isEqualToString:cw]) { //Exclude the ones that are the same. Example: Al is same as Al
                    NSLog(@"%@ is same as %@",pw , cw); //Just print the ones that are the same with caseInsensitiveCompare comparative
                }
            }
        }
    }
}
return 0;

}
[/code]

The out put is:

2013-08-07 12:45:10.497 Challenge 15 NSArray[467:303] Al is same as al
2013-08-07 12:45:10.562 Challenge 15 NSArray[467:303] Alan is same as alan
2013-08-07 12:45:10.752 Challenge 15 NSArray[467:303] Alf is same as alf
2013-08-07 12:45:10.802 Challenge 15 NSArray[467:303] Alison is same as alison
2013-08-07 12:45:10.827 Challenge 15 NSArray[467:303] Allan is same as allan
2013-08-07 12:45:10.968 Challenge 15 NSArray[467:303] Ami is same as ami
2013-08-07 12:45:11.013 Challenge 15 NSArray[467:303] Amir is same as amir
2013-08-07 12:45:11.064 Challenge 15 NSArray[467:303] Amy is same as amy
2013-08-07 12:45:11.378 Challenge 15 NSArray[467:303] Ann is same as ann

2013-08-07 12:46:08.936 Challenge 15 NSArray[472:303] Walter is same as walter
2013-08-07 12:46:08.963 Challenge 15 NSArray[472:303] Warren is same as warren
2013-08-07 12:46:09.115 Challenge 15 NSArray[472:303] Will is same as will
2013-08-07 12:46:09.159 Challenge 15 NSArray[472:303] Willie is same as willie
2013-08-07 12:46:09.228 Challenge 15 NSArray[472:303] Win is same as win
2013-08-07 12:46:09.295 Challenge 15 NSArray[472:303] Wolf is same as wolf
2013-08-07 12:46:09.345 Challenge 15 NSArray[472:303] Woody is same as woody