Skip to content

Instantly share code, notes, and snippets.

@akaneko3
Created October 25, 2014 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaneko3/10dd3a0d380d80184cbb to your computer and use it in GitHub Desktop.
Save akaneko3/10dd3a0d380d80184cbb to your computer and use it in GitHub Desktop.
Factorial with Rust
use std::iter::range_inclusive;
fn main() {
let fact = |n: uint| { range_inclusive(1, n).fold(1, |a, b| a * b) };
let nums = [3, 5, 0];
for num in nums.iter() { println!("{}", fact(*num)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment