Created
November 22, 2013 04:57
-
-
Save SaitoAtsushi/7595054 to your computer and use it in GitHub Desktop.
10000 のフィボナッチ数を計算して 20 桁ごとに行を区切って表示するプログラム。
ajhc でコンパイルすると誤った値が出力される。
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.List | |
| data Mat a = Mat a a a a deriving (Show, Eq) | |
| instance (Num a) => Num (Mat a) where | |
| (Mat a b c d) * (Mat p q r s) = Mat (a*p+b*r) (a*q+b*s) (c*p+d*r) (c*q+d*s) | |
| (Mat a b c d) + (Mat p q r s) = Mat (a+p) (b+q) (c+r) (d+s) | |
| abs=undefined | |
| signum=undefined | |
| fromInteger x = let y = fromInteger x in (Mat y y y y) | |
| fibonacci :: Integer -> Integer | |
| fibonacci n = case (Mat 1 1 1 0) ^ n of Mat a b c d -> b | |
| splitInto :: Int->[a]->[[a]] | |
| splitInto n = unfoldr (\x->if null x then Nothing else Just $ splitAt n x) | |
| main :: IO () | |
| main = mapM_ putStrLn $ splitInto 20 $ show $ fibonacci 10000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment