m1759
m1759

Reputation: 35

Finding the sum of a list then dividing it with a certain number Haskell

addDivide n = if sum n / 5 then True else False

I am trying to get the sum of a list then see if the sum is divisible by a certain number

eg. [5,5] = 10/5 = 2

Upvotes: 0

Views: 142

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477160

You can check if an Integral number a is dividable by 5, by check if n `mod` 5 == 0.

You thus can check this with:

addDivide :: (Foldable f, Integral a) => f a -> Bool
addDivide xs = sum xs `mod` 5 == 0

Upvotes: 1

Related Questions