Fibonacci sequence: Difference between revisions

Content added Content deleted
(Added Odin Language Iterative Solution)
Line 9,837:
Odin Build: dev-2023-07-nightly:3072479c
<syntaxhighlight lang="odin">
// Packge Name and Imports
package fib
import "core:fmt"
 
// Global Variable Declarations
prev: u128 = 0
current: u128 = 1
next: u128
 
// Main proc
main :: proc() {
fmt.println("\nFibonacci Seq - starting n and n+1 from 0 and 1:")
Line 9,855 ⟶ 9,848:
}
 
// Procedures
fibi :: proc(n: u128) -> u128 {
if n < 2 {
return n
}
} else {
for i: u128 = 2;a, ib: u128 <= n; i +=0, 1 {
for _ in 2..=n {
next = prev + current
a += b
prev = current
a, b = b, a
current = next
}
return current
return 0b
}
}
return 0
}
 
// End of Source Code
</syntaxhighlight>
{{out}}