Skip to content

Instantly share code, notes, and snippets.

@Javran
Created September 14, 2012 03:12
Show Gist options
  • Select an option

  • Save Javran/3719575 to your computer and use it in GitHub Desktop.

Select an option

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?
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
@Javran

Javran commented Sep 14, 2012

Copy link
Copy Markdown
Author

you MUST compile this program using optimization, or your memory space will be eaten up...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment