Created
August 6, 2011 05:52
-
-
Save isomorphism/1129054 to your computer and use it in GitHub Desktop.
quick and stupid benchmarking example
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 | |
import System.Environment | |
{- RE: http://stackoverflow.com/q/6964392/157360 | |
cam@atomos:~/scraps/SO/euler$ ghc -O2 --make Euler12.hs | |
cam@atomos:~/scraps/SO/euler$ time ./Euler12 1000 | |
842161320 | |
real 0m12.892s | |
user 0m12.885s | |
sys 0m0.000s | |
cam@atomos:~/scraps/SO/euler$ gcc -O3 -lm -o euler12c euler12.c | |
cam@atomos:~/scraps/SO/euler$ time ./euler12c | |
842161320 | |
real 0m12.029s | |
user 0m11.977s | |
sys 0m0.000s | |
-} | |
triangleNums :: [Int] | |
triangleNums = scanl1 (+) [1..] | |
factorCount :: Int -> Int | |
factorCount n = (+ seed) . (* 2) . length . filter (0 ==) . map (rem n) $ [1..intSqrt] | |
where intSqrt = floor . sqrt $ fromIntegral n | |
seed = if sqrt (fromIntegral n) == fromIntegral intSqrt | |
then -1 | |
else 0 | |
euler12 :: Int -> Int | |
euler12 n = head $ filter ((> n) . factorCount) triangleNums | |
main = do [n] <- getArgs | |
print . euler12 $ read n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment