#!/usr/bin/ruby

#
## The Ackermann function
#

class Ackermann {
    method A({ .is_zero }, n) {
        n + 1
    }

    method A(m, (0)) {
        self.A(m-1, 1)
    }

    method A(m, n) {
        self.A(m-1, self.A(m, n-1))
    }
}

var obj = Ackermann();
assert_eq(obj.A(3, 2), 29);


#
## The Fibonacci Nth term
#

class Fib {
    method nth(Number n { _ <= 1 } = 0) {
        return n
    }

    method nth(n) {
        self.nth(n-1) + self.nth(n-2)
    }
}

var f = Fib();
assert_eq(f.nth(), 0);
assert_eq(f.nth(12), 144);


#
## The Fibonacci Nth term (#2)
#

class Fib2 {
    method nth((0)) { 0 }
    method nth((1)) { 1 }
    method nth (n)  { self.nth(n-1) + self.nth(n-2) }
}

var f2 = Fib2();
assert_eq(f2.nth(12), 144);

say "** Test passed!";