Skip to content

Instantly share code, notes, and snippets.

@haldun
Created December 23, 2013 17:43
Show Gist options
  • Save haldun/8101433 to your computer and use it in GitHub Desktop.
Save haldun/8101433 to your computer and use it in GitHub Desktop.
fibonacci in haskell
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