multipleOf m n = m `mod` n == 0
chosenNumbers = filter (\x -> x `multipleOf` 3 || x `multipleOf` 5) [1..999]
main = print ( sum chosenNumbers )
Ach nuair a léigh mé an fóram, chonaic mé an chaoi is fearr liom:
sum [n | n <- [1..999], n `mod` 5 == 0 || n `mod` 3 == 0]
I'm learning Haskell now. It's a functional programming language (functional in the mathematical sense). And I came across Project Euler recently, which has short maths problems that are great for practising programming. The first bit of code is my own solution; the second is a much better one that I found on the forum.