
Untitled
By: a guest on
Sep 18th, 2012 | syntax:
None | size: 0.45 KB | hits: 14 | expires: Never
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)