Skip to content

Instantly share code, notes, and snippets.

@sassy
Created February 5, 2012 13:48
Show Gist options
  • Save sassy/1745669 to your computer and use it in GitHub Desktop.
Save sassy/1745669 to your computer and use it in GitHub Desktop.
rustでpascal's triangle
use std;
fn factorial(n: int) -> int {
if n == 0 {ret 1; }
else {ret n * factorial(n - 1); }
}
fn bt(n: int, k: int) -> int {
ret factorial(n) / (factorial(n -k) * factorial(k));
}
fn pascal(k: int) {
let i = 0;
while i <= k {
let j = 0;
while j <= i {
std::io::print(int::str(bt(i, j)) + " ");
j += 1;
}
std::io::println("");
i += 1;
}
}
fn main() {
pascal(6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment