Scala

By jbgreer

This is mainly a test to confirm that WordPress respects the pre tag such that I can post code snippets and that WordPress’ \LaTeX functionality works.

package fibonnaci;

object RecursiveFibonnaci {

    // Fibonnacci using if/else.  Note implicit return
    def fib(n: int): int = {
        if (n == 0)  0
        else if (n == 1) 1
        else fib(n-2) + fib(n-1)
    };
}

That’s a simple example of the Fibonnaci function f(n) = f(n-2) + f(n-1) with f(0) = 0 and f(1) = 1.

Tags:

Leave a Reply

You must be logged in to post a comment.