Created
December 26, 2016 11:51
-
-
Save binho/3466ffeda17a55c690ba8d0b60b12c57 to your computer and use it in GitHub Desktop.
Fibonnaci Objective-C (Returns an array)
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
- (NSArray *)fibonnaci:(NSNumber *)number { | |
NSMutableArray *array = [NSMutableArray new]; | |
for (int i = 0; i < [number intValue]; i++) { | |
if (i < 2) { | |
[array addObject:@(i)]; | |
} else { | |
int fib = ([array[i-1] intValue] + [array[i-2] intValue]); | |
[array addObject:@(fib)]; | |
} | |
} | |
NSLog(@"Fibo: %@", array); | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment