Skip to content

Instantly share code, notes, and snippets.

@apparentsoft
Created August 5, 2012 06:48
Show Gist options
  • Save apparentsoft/3262453 to your computer and use it in GitHub Desktop.
Save apparentsoft/3262453 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment