Last active
May 8, 2017 13:13
-
-
Save htsign/5d1640ef9ff15706e669e29ef0c53ba0 to your computer and use it in GitHub Desktop.
fibonacci algorism implementation of Nemerle with memoization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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