Created
March 31, 2012 01:18
-
-
Save dneto/2258454 to your computer and use it in GitHub Desktop.
Factorial recursive algorithm in Rust language
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
fn factorial(value: int) -> int { | |
if value==0 { ret 1; } | |
else { ret value * factorial(value-1); } | |
} | |
fn main(args: [str]) { | |
let init_value = option::get(int::from_str(args[1])); | |
let final_value = int::str(factorial(init_value)); | |
io::println(final_value); | |
} |
My dude this is a Gist from 2012.
Just in-case (noone wanted this) anyone wanted it updated to 2020
fn factorial(x: i32) -> i32 {
if x == 0 {
1
} else {
x * factorial(x-1)
}
}
Yes, this is a code from, maybe, alpha or pre-alpha rust. I was just trying to learn it.
The language changed over the time until the initial version was released, so this code doesn't run anymore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like Java, It won't work...
Change:
-int to i32
-remove args:[str]
-Why you need to do io::println? It's supposed to be "println!"