Last active
August 29, 2015 14:22
-
-
Save orkoden/a04cb40f3997e38dd62f to your computer and use it in GitHub Desktop.
Fizzbuzz in Objective-C that works without if, modulo, lookup table
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
#import <Foundation/Foundation.h> | |
NSMutableArray* fizzbuzzreplace(NSMutableArray* numberArray, NSUInteger divider, NSString* replacementString) | |
{ | |
for (NSUInteger i = divider; i < numberArray.count + 1; i = i + divider) { | |
[numberArray replaceObjectAtIndex:i - 1 withObject:replacementString]; | |
} | |
return numberArray; | |
} | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSMutableArray* numbersTo100 = [NSMutableArray arrayWithCapacity:100]; | |
for (NSUInteger i = 1; i < 101; ++i) { | |
[numbersTo100 addObject:[NSNumber numberWithUnsignedInteger:i]]; | |
} | |
fizzbuzzreplace(fizzbuzzreplace(fizzbuzzreplace(numbersTo100, 3, @"Fizz"), 5, @"Buzz"), 15, @"FizzBuzz"); | |
NSLog(@"%@", [numbersTo100 description]); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment