Skip to content

Instantly share code, notes, and snippets.

@binho
Created December 26, 2016 11:51
Show Gist options
  • Save binho/3466ffeda17a55c690ba8d0b60b12c57 to your computer and use it in GitHub Desktop.
Save binho/3466ffeda17a55c690ba8d0b60b12c57 to your computer and use it in GitHub Desktop.
Fibonnaci Objective-C (Returns an array)
- (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