Created
November 28, 2016 11:06
-
-
Save epequeno/d5e185391b3a0ddba7d6a06023ec6d6d to your computer and use it in GitHub Desktop.
fibo in rust
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
fn main() { | |
for x in 1..11 { | |
println!("{} -> {}", x, fibo(x)); | |
} | |
} | |
fn fibo(n: i32) -> f64 { | |
let phi = (1_f64 + 5_f64.sqrt()) / 2_f64; | |
(phi.powf(n as f64) / 5_f64.sqrt()).round() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment