import Data.Set
euler :: Int
euler = sum [ x | x <- nums ]
where
nums = Data.Set.toList (Data.Set.union (Data.Set.fromList [3,6..999])
(Data.Set.fromList [5,10..999]))
I am learning Haskell and hope you don't mind me asking this. Is there a nicer way to get a list holding all natural numbers below one thousand that are multiples of 3 or 5? (E.g. with zip or map?)
Edit:
import Data.List
euler :: Int
euler = sum (union [3,6..999] [5,10..999])
Thanks for your help, guys.
[x | x <- nums]is better spellednums. - Daniel WagnerData.List.unionis inefficient, of quadratic time complexity. - Will Ness