Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
Created March 11, 2015 20:17
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 seanlilmateus/f4904df749895c2fc63e to your computer and use it in GitHub Desktop.
Save seanlilmateus/f4904df749895c2fc63e to your computer and use it in GitHub Desktop.
Rust (rustc 1.0.0-nightly) generic factorial
use std::num::Int;
fn factorial<T: Int>(num: &T) -> T {
if *num == T::zero() || *num == T::one() {
T::one()
} else {
*num * factorial(&(*num - T::one()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment