Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
10
Task/Fibonacci-sequence/Objective-C/fibonacci-sequence-1.m
Normal file
10
Task/Fibonacci-sequence/Objective-C/fibonacci-sequence-1.m
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
-(long)fibonacci:(int)position
|
||||
{
|
||||
long result = 0;
|
||||
if (position < 2) {
|
||||
result = position;
|
||||
} else {
|
||||
result = [self fibonacci:(position -1)] + [self fibonacci:(position -2)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
+(long)fibonacci:(int)index {
|
||||
long beforeLast = 0, last = 1;
|
||||
while (index > 0) {
|
||||
last += beforeLast;
|
||||
beforeLast = last - beforeLast;
|
||||
--index;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue