Created
October 15, 2017 08:17
-
-
Save evertrol/a0e3c94490724a1de9028a94dc0260e9 to your computer and use it in GitHub Desktop.
This file contains 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
/// Rust Fibonacci one-liner using `fold` | |
/// | |
/// Not very practical: only for one time use, | |
/// since it will have to re-calculate all terms again and again | |
/// if used in a loop to create multiple items. | |
/// The use of `_` also suggests this is not an ideal solution. | |
fn main() { | |
let n = 10; | |
let x = (0..n).fold((0, 1), |x, _| (x.0+x.1, x.0)).0; | |
println!("{}: {}", n, x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment