Skip to content

Instantly share code, notes, and snippets.

@todashuta
Created February 1, 2020 05:19
Show Gist options
  • Select an option

  • Save todashuta/5cac24f14eff997e2716ded7669bb2e6 to your computer and use it in GitHub Desktop.

Select an option

Save todashuta/5cac24f14eff997e2716ded7669bb2e6 to your computer and use it in GitHub Desktop.
rust
fn fac(n: i32) -> i32 {
if n <= 1 {
1
} else {
n * fac(n-1)
}
}
fn tarai(x: i32, y: i32, z: i32) -> i32 {
if x <= y {
y
} else {
tarai(tarai(x-1,y,z), tarai(y-1,z,x), tarai(z-1,x,y))
}
}
fn main() {
let n = 4;
println!("factorial({}) = {}", n, fac(n).to_string());
println!("tarai(15, 5, 0) = {}", tarai(15, 5, 0).to_string());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment