[Haskell-cafe] how to optmize this code?

Gilberto Garcia giba.dmb at gmail.com
Wed Mar 30 16:39:49 CEST 2011

Hi Haskellers,

I was solving this problem from project euler to study haskell.
I came up whit the following solution and I was wondering if there is
a more optimized and concise solution.

fkSum :: Int -> [Int] -> Int
fkSum a [] = 0
fkSum a (b) = foldl (+) 0 (filter (\x -> isMultiple x b) [1..a])

isMultiple :: Int -> [Int] -> Bool
isMultiple a [] = False
isMultiple a (x:xs) = if (mod a x == 0) then True else isMultiple a xs

Thanks in advance

More information about the Haskell-Cafe mailing list