Created
September 14, 2012 03:12
-
-
Save Javran/3719575 to your computer and use it in GitHub Desktop.
project euler p-104, why did this program eat up all my memory space?
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
import Data.Char | |
import Data.List | |
fibSeq :: [(Integer, Integer)] | |
fibSeq = map (\(n, (a,_)) -> (n, a)) $ iterate (\(n, (a,b))->(n+1, (b,a+b))) (1,(1,1)) | |
fstPandigital :: Integer -> Bool | |
fstPandigital n = charNum == "123456789" where | |
charNum = sort $ take 9 $ show n | |
lstPandigital :: Integer -> Bool | |
lstPandigital n = charNum == "123456789" where | |
charNum = sort $ show $ n `mod` 1000000000 | |
result = fst $ head $ filter (\(n, x)-> (lstPandigital x) && (fstPandigital x) ) fibSeq | |
main = print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you MUST compile this program using optimization, or your memory space will be eaten up...