Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add1 xs n c
- | c < 0 = reverse $ add1 (reverse xs) n (abs c)
- | c > 0 = add1' xs n c
- | c == 0 = add1' xs n (length xs)
- where
- add1' [] _ _ = []
- add1' xs n 0 = xs
- add1' (x:xs) n c
- | x == n = x+1:(add1' xs n (c-1))
- | otherwise = x:add1' xs n c
- -- Below are the test runs
- param = [1,4,1,5,1]
- main :: IO ()
- main = do
- putStrLn . show $ param
- putStrLn . show $ add1 param 1 0
- putStrLn . show $ add1 param 1 2
- putStrLn . show $ add1 param 1 (-2)
Advertisement
Add Comment
Please, Sign In to add comment