Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
fibonacci algorism implementation of Nemerle with memoization
using Nemerle;
using System.Console;
using System.Numerics;
module Program
{
Main() : void
{
def fib(n)
{
WriteLine("{0,8} : {1}", n, Fibonacci(n));
when (n % 10 == 0) _ = ReadLine();
fib(n + 1);
}
fib(1);
}
[Memoize]
Fibonacci(n : int) : BigInteger
{
| _ when n <= 1 => 1
| _ => Fibonacci(n - 1) + Fibonacci(n - 2)
}
}
#pragma indent
using Nemerle
using System.Console
using System.Numerics
module Program
Main() : void
def fib(n)
WriteLine("{0,8} : {1}", n, Fibonacci(n))
when (n % 10 == 0) _ = ReadLine()
fib(n + 1)
fib(1)
[Memoize] \
Fibonacci(n : int) : BigInteger
| _ when n <= 1 => 1
| _ => Fibonacci(n - 1) + Fibonacci(n - 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment