RosettaCodeData/Task/Fibonacci-sequence/Objective-C/fibonacci-sequence-2.m

10 lines
199 B
Mathematica
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
+(long)fibonacci:(int)index {
long beforeLast = 0, last = 1;
while (index > 0) {
last += beforeLast;
beforeLast = last - beforeLast;
--index;
}
return last;
}