Created
December 23, 2013 17:43
-
-
Save haldun/8101433 to your computer and use it in GitHub Desktop.
fibonacci in haskell
This file contains hidden or 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
import Data.Ratio | |
data Q5 = Rational :+ Rational deriving (Show) | |
instance Num Q5 where | |
(a :+ b) + (c :+ d) = (a + c) :+ (b + d) | |
(a :+ b) * (c :+ d) = (a * c + 5 * b * d) :+ (a * d + b * c) | |
phi = (1 % 2) :+ (1 % 2) | |
fib n = let a :+ b = phi ^ n in round(2 * b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment