RosettaCodeData/Task/Fibonacci-sequence/Gleam/fibonacci-sequence-2.gleam
2026-04-30 12:34:36 -04:00

10 lines
216 B
Gleam

pub fn fib(n: Int) -> Int {
fib_helper(n, 0, 1)
}
fn fib_helper(n: Int, res: Int, next: Int) -> Int {
case n, res, next {
0, res, _ -> res
iter, res, next -> fib_helper(iter - 1, next, res + next)
}
}