Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main :: IO()
- main = do
- print $ removeFistOccurrence 110 1 == 10
- print $ removeFistOccurrence 15365 5 == 1536
- print $ removeFistOccurrence 15360 0 == 1536
- print $ removeFistOccurrence 15300 0 == 1530
- print $ removeFistOccurrence 15365 1 == 5365
- print $ removeFistOccurrence 35365 3 == 3565
- print $ removeFistOccurrence 1212 1 == 122
- print $ removeFistOccurrence 1212 2 == 121
- print $ removeFistOccurrence (removeFistOccurrence 1212 1) 1 == 22
- removeFistOccurrence :: Int -> Int -> Int
- removeFistOccurrence d n = helper 0 0 n
- where
- helper result pow number
- | number == 0 = result
- | mod number 10 /= d = helper (mod number 10 * 10^pow + result) (pow + 1) (div number 10)
- | otherwise = helper result pow (div number 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement