aboutsummaryrefslogtreecommitdiff
path: root/src/test/bench/shootout/fibo.rs
blob: 8fc95f895c2ba17d1b71e0a46a4820db2050b951 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// -*- rust -*-

fn fib(int n) -> int {
  // Several of the posted 'benchmark' versions of this compute the
  // wrong Fibonacci numbers, of course.
  if (n == 0) {
    ret 0;
  } else {
    if (n <= 2) {
      ret 1;
    } else {
      ret fib(n-1) + fib(n-2);
    }
  }
}

fn main() {
  assert (fib(8) == 21);
  assert (fib(15) == 610);
  log fib(8);
  log fib(15);
}