Skip to content

Instantly share code, notes, and snippets.

Created Mar 31, 2012
What would you like to do?
Factorial recursive algorithm in Rust language
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));
Copy link

Z34O commented May 23, 2017

Looks like Java, It won't work...
-int to i32
-remove args:[str]
-Why you need to do io::println? It's supposed to be "println!"

Copy link

ghost commented May 24, 2018

My dude this is a Gist from 2012.

Copy link

codedcosmos commented Jan 6, 2021

Just in-case (noone wanted this) anyone wanted it updated to 2020

fn factorial(x: i32) -> i32 {
    if x == 0 {
    } else {
        x * factorial(x-1)

Copy link

dneto commented Jan 6, 2021

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