12 lines
266 B
Text
12 lines
266 B
Text
|
|
func fibonacci(num: Integer): Integer {
|
||
|
|
require num >= 0;
|
||
|
|
var previous = 1;
|
||
|
|
var current = 0;
|
||
|
|
for (val _ in range(1, num, :incl)) {
|
||
|
|
val next = current + previous;
|
||
|
|
previous = current;
|
||
|
|
current = next;
|
||
|
|
}
|
||
|
|
return current;
|
||
|
|
}
|