Create a gist now

Instantly share code, notes, and snippets.

@htsign /fibonacci.n
Last active Dec 13, 2016

What would you like to do?
fast fibonacci algorism implementation of 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);
}
Fibonacci(n : int) : BigInteger
{
mutable a = BigInteger.Zero;
mutable b = BigInteger.One;
foreach (i in [31, 30..0])
{
(a, b) = (a * (b * 2 - a), a * a + b * b);
when (((n :> uint >> i) & 1) != 0)
{
(a, b) = (b, a + b);
}
}
a;
}
}
#pragma indent
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)
Fibonacci(n : int) : BigInteger
mutable a = BigInteger.Zero
mutable b = BigInteger.One
foreach (i in [31, 30..0])
(a, b) = (a * (b * 2 - a), a * a + b * b)
when (((n :> uint >> i) & 1) != 0)
(a, b) = (b, a + b)
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment