Skip to content

Instantly share code, notes, and snippets.

@htsign
Last active May 8, 2017 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htsign/5d1640ef9ff15706e669e29ef0c53ba0 to your computer and use it in GitHub Desktop.
Save htsign/5d1640ef9ff15706e669e29ef0c53ba0 to your computer and use it in GitHub Desktop.
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