I\'m currently working on project euler problem 14.
I solved it using a poorly coded program, without memoization, that took 386 5 seconds to run (s
Well, the C program uses unsigned long
, but Integer
can store arbitrarily large integers (it's a bignum). If you import Data.Word, then you can use Word
, which is a machine-word-sized unsigned integer.
After replacing Integer
with Word
, and using ghc -O2
and gcc -O3
, the C program runs in 0.72 seconds, while the Haskell programs runs in 1.92 seconds. 2.6x isn't bad. However, ghc -O2
doesn't always help, and this is one of the programs on which it doesn't! Using just -O
, as you did, brings the runtime down to 1.90 seconds.
I tried replacing div
with quot
(which uses the same type of division as C; they only differ on negative inputs), but strangely it actually made the Haskell program run slightly slower for me.
You should be able to speed up the syr
function with the help of this previous Stack Overflow question I answered about the same Project Euler problem.