Advertisement
darinab

Untitled

Apr 5th, 2023
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main :: IO()
  2. main = do
  3.    print $ removeFistOccurrence 110 1 == 10
  4.    print $ removeFistOccurrence 15365 5 == 1536
  5.    print $ removeFistOccurrence 15360 0 == 1536
  6.    print $ removeFistOccurrence 15300 0 == 1530
  7.    print $ removeFistOccurrence 15365 1 == 5365
  8.    print $ removeFistOccurrence 35365 3 == 3565
  9.    print $ removeFistOccurrence 1212 1 == 122
  10.    print $ removeFistOccurrence 1212 2 == 121
  11.    print $ removeFistOccurrence (removeFistOccurrence 1212 1) 1 == 22
  12.  
  13. removeFistOccurrence :: Int -> Int -> Int
  14. removeFistOccurrence d n = helper 0 0 n
  15.  where
  16.     helper result pow number
  17.      | number == 0 = result
  18.      | mod number 10 /= d = helper (mod number 10 * 10^pow + result) (pow + 1) (div number 10)
  19.      | otherwise = helper result pow (div number 10)
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement