Created
May 29, 2023 18:46
-
-
Save isaacharrisholt/4aa158b7bc7e8787d221baeee55dbea9 to your computer and use it in GitHub Desktop.
Fibonacci - Rust implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use pyo3::prelude::*; | |
/// Calculate the nth Fibonacci number. | |
#[pyfunction] | |
fn fib(n: u32) -> u32 { | |
if n <= 1 { | |
return n; | |
} | |
fib(n - 1) + fib(n - 2) | |
} | |
/// Fast Fibonacci number calculation. | |
#[pymodule] | |
fn fibbers(_py: Python, m: &PyModule) -> PyResult<()> { | |
m.add_function(wrap_pyfunction!(fib, m)?)?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment