Last active
March 24, 2021 02:27
-
-
Save jkereako/7045ff77c2021845262c to your computer and use it in GitHub Desktop.
Finds the symmetric difference between 2 sets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // symmetric-difference.m | |
| // RosettaCodeData | |
| // | |
| // Created by Ingy döt Net on 4/2/14. | |
| // https://github.com/acmeism/RosettaCodeData/blob/master/Task/Symmetric-difference/Objective-C/symmetric-difference.m | |
| // | |
| #import <Foundation/Foundation.h> | |
| int main(int argc, const char *argv[]) { | |
| @autoreleasepool { | |
| NSSet *setA = [NSSet setWithObjects:@"John", @"Serena", @"Bob", @"Mary", @"Serena", nil]; | |
| NSSet *setB = [NSSet setWithObjects:@"Jim", @"Mary", @"John", @"Jim", @"Bob", nil]; | |
| // Present our initial data set | |
| NSLog(@"In set A: %@", setA); | |
| NSLog(@"In set B: %@", setB); | |
| // Get our individual differences. | |
| NSMutableSet* notInSetA = [NSMutableSet setWithSet:setB]; | |
| [notInSetA minusSet:setA]; | |
| NSMutableSet* notInSetB = [NSMutableSet setWithSet:setA]; | |
| [notInSetB minusSet:setB]; | |
| // The symmetric difference is the concatenation of the two individual differences | |
| NSMutableSet* symmetricDifference = [NSMutableSet setWithSet:notInSetA]; | |
| [symmetricDifference unionSet:notInSetB]; | |
| // Present our results | |
| NSLog(@"Not in set A: %@", notInSetA); | |
| NSLog(@"Not in set B: %@", notInSetB); | |
| NSLog(@"Symmetric Difference: %@", symmetricDifference); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
This Gist shows a way of finding the symmetric difference between 2 sets.
Usage
Compile with this command
And execute with this command
$ .\symmetric-differenceCredit
I manually forked this from ingydotnet.