Advertisement
vencinachev

Tech support

Nov 22nd, 2020 (edited)
1,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2. numberToDigits :: Int -> [Int]
  3. numberToDigits 0 = []
  4. numberToDigits n = (mod n 10) : numberToDigits (div n 10)
  5.  
  6. minDigit :: Int -> Int
  7. minDigit 0 = 0
  8. minDigit n = foldr1 min (numberToDigits n)
  9.  
  10. digitsSum :: Int -> Int
  11. digitsSum 0 = 0
  12. digitsSum n = (mod n 10) + digitsSum (div n 10)
  13.  
  14. digitsCount :: Int -> Int
  15. digitsCount 0 = 0
  16. digitsCount n = 1 + digitsCount (div n 10)
  17.  
  18. digitsAvgF :: Int -> Float
  19. digitsAvgF num = (fromIntegral (digitsSum num)) / (fromIntegral  (digitsCount num))
  20.  
  21. digitsAvgI :: Int -> Int
  22. digitsAvgI num = div (digitsSum num) (digitsCount num)
  23.  
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement