Created
March 18, 2013 22:50
-
-
Save coderd00d/5191610 to your computer and use it in GitHub Desktop.
122 Challenge
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
// | |
// main.m | |
// Easy Challenge #122 words with ordered vowels. | |
// | |
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSArray *words; | |
NSString *word; | |
NSString *fileString = nil; | |
NSString *filePath = @"/Users/enable1.txt"; | |
NSError *error; | |
NSUInteger numOfMatches; | |
NSRegularExpression *searchPattern; | |
NSData *rawData = [NSData dataWithContentsOfFile: filePath]; | |
if (!rawData) { | |
NSLog(@"Error opening file or reading file!"); | |
return 1; | |
} | |
fileString = [[NSString alloc] initWithData: rawData encoding: NSUTF8StringEncoding]; | |
if (!fileString) { | |
NSLog(@"Error converting raw data to string"); | |
return 1; | |
} | |
words = [fileString componentsSeparatedByString:@"\n"]; | |
if (!words) { | |
NSLog(@"Error Separating out Strings"); | |
return 1; | |
} | |
for (word in words) { | |
if ([word length] >= 6) | |
{ | |
searchPattern = [NSRegularExpression | |
regularExpressionWithPattern: @"[b-d | f-h | j-n | p-t | v-x | z]*a[b-d | f-h | j-n | p-t | v-x | z]*e[b-d | f-h | j-n | p-t | v-x | z]*i[b-d | f-h | j-n | p-t | v-x | z]*o[b-d | f-h | j-n | p-t | v-x | z]*u[b-d | f-h | j-n | p-t | v-x | z]*y[b-d | f-h | j-n | p-t | v-x | z]*" | |
options: NSRegularExpressionCaseInsensitive | |
error: &error]; | |
numOfMatches = [searchPattern numberOfMatchesInString: word | |
options: 0 | |
range: NSMakeRange(0, [word length])]; | |
if (numOfMatches > 0) | |
NSLog(@"%@", word); | |
} | |
searchPattern = nil; | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment