On Wed, Mar 30, 2011 at 2:39 PM, Gilberto Garcia <[email protected]> wrote:
> fkSum :: Int -> [Int] -> Int
> fkSum a [] = 0
> fkSum a (b) = foldl (+) 0 (filter (\x -> isMultiple x b) [1..a])

Daniel Fischer and Yves Parès gave you good suggestions about
implementing a different, better algorithm for you problem.  However,
there's one small thing about your current code.  Instead of foldl,
you should use foldl' (use "import Data.List"), which is strict in the
accumulator.  Most of the time you want foldl' instead of foldl.  You
can learn more about the list folds here [1].

HTH,

[1] http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27

-- 
Felipe.

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to