Created
August 5, 2012 06:48
-
-
Save apparentsoft/3262453 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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