RosettaCodeData/Task/Symmetric-difference/Objective-C/symmetric-difference.m

31 lines
1,016 B
Mathematica
Raw Permalink Normal View History

2014-04-02 16:56:35 +00:00
#import <Foundation/Foundation.h>
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
int main(int argc, const char *argv[]) {
@autoreleasepool {
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
NSSet* setA = [NSSet setWithObjects:@"John", @"Serena", @"Bob", @"Mary", @"Serena", nil];
NSSet* setB = [NSSet setWithObjects:@"Jim", @"Mary", @"John", @"Jim", @"Bob", nil];
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
// Present our initial data set
NSLog(@"In set A: %@", setA);
NSLog(@"In set B: %@", setB);
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
// Get our individual differences.
NSMutableSet* notInSetA = [NSMutableSet setWithSet:setB];
[notInSetA minusSet:setA];
NSMutableSet* notInSetB = [NSMutableSet setWithSet:setA];
[notInSetB minusSet:setB];
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
// The symmetric difference is the concatenation of the two individual differences
NSMutableSet* symmetricDifference = [NSMutableSet setWithSet:notInSetA];
[symmetricDifference unionSet:notInSetB];
2013-04-11 01:07:29 -07:00
2014-04-02 16:56:35 +00:00
// Present our results
NSLog(@"Not in set A: %@", notInSetA);
NSLog(@"Not in set B: %@", notInSetB);
NSLog(@"Symmetric Difference: %@", symmetricDifference);
}
return 0;
}