Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Anonymous-recursion/Objective-C/anonymous-recursion-2.m
Normal file
26
Task/Anonymous-recursion/Objective-C/anonymous-recursion-2.m
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int fib(int n) {
|
||||
if (n < 0)
|
||||
@throw [NSException exceptionWithName:NSInvalidArgumentException
|
||||
reason:@"fib: no negative numbers"
|
||||
userInfo:nil];
|
||||
int (^f)(int);
|
||||
__block __weak int (^weak_f)(int); // block cannot capture strong reference to itself
|
||||
weak_f = f = ^(int n) {
|
||||
if (n < 2)
|
||||
return 1;
|
||||
else
|
||||
return weak_f(n-1) + weak_f(n-2);
|
||||
};
|
||||
return f(n);
|
||||
}
|
||||
|
||||
int main (int argc, const char *argv[]) {
|
||||
@autoreleasepool {
|
||||
|
||||
NSLog(@"%d", fib(8));
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue