Guest User

Untitled

a guest
Jan 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. sumDigits :: Int -> Int
  2. -- Adds together each digit of given number
  3.  
  4. sumDigits n
  5.  
  6. | n <= 9 = n
  7. | n >= 10 = ( n `mod` 10 ) + sumDigits ( n `div` 10 )
  8.  
  9.  
  10. sumAllDigits :: [Int] -> Int
  11. -- Adds together each digit of given list
  12.  
  13. sumAllDigits [] = 0
  14. sumAllDigits ( x : xs ) = ( SumDigits x ) + ( sumAllDigits xs )
Add Comment
Please, Sign In to add comment