Created
July 22, 2012 19:25
-
-
Save boredzo/3160779 to your computer and use it in GitHub Desktop.
Comparing character sets
This file contains 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
#import <Foundation/Foundation.h> | |
int main(int argc, char **argv) { | |
@autoreleasepool { | |
NSCharacterSet *charactersInWord = [NSCharacterSet characterSetWithCharactersInString:@"secretagogue"]; | |
NSMutableCharacterSet *guessedCharacters = [NSMutableCharacterSet characterSetWithCharactersInString:@""]; | |
[guessedCharacters addCharactersInString:@"s"]; | |
[guessedCharacters addCharactersInString:@"e"]; | |
[guessedCharacters addCharactersInString:@"c"]; | |
[guessedCharacters addCharactersInString:@"r"]; | |
//[guessedCharacters addCharactersInString:@"e"]; | |
[guessedCharacters addCharactersInString:@"t"]; | |
[guessedCharacters addCharactersInString:@"a"]; | |
[guessedCharacters addCharactersInString:@"g"]; | |
[guessedCharacters addCharactersInString:@"o"]; | |
//[guessedCharacters addCharactersInString:@"g"]; | |
[guessedCharacters addCharactersInString:@"u"]; | |
//[guessedCharacters addCharactersInString:@"e"]; | |
//Fun bonus variant: Uncomment the above lines and see what result you get then. | |
//Fun bonus variant #2: Uncomment either or both of the following lines instead. | |
//charactersInWord = [NSCharacterSet characterSetWithBitmapRepresentation:[charactersInWord bitmapRepresentation]]; | |
//guessedCharacters = [NSMutableCharacterSet characterSetWithBitmapRepresentation:[guessedCharacters bitmapRepresentation]]; | |
//Fun bonus variant #3: Uncomment the following line. | |
//[guessedCharacters formIntersectionWithCharacterSet:guessedCharacters]; | |
NSLog(@"%@", [guessedCharacters isEqual:charactersInWord] ? @"YES": @"NO"); | |
} | |
return EXIT_SUCCESS; | |
} |
This file contains 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
2012-07-22 12:24:19.948 cmpcs[22579:707] NO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment