Guest User

Untitled

a guest
Sep 18th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. add1 xs n c
  2. | c < 0 = reverse $ add1 (reverse xs) n (abs c)
  3. | c > 0 = add1' xs n c
  4. | c == 0 = add1' xs n (length xs)
  5. where
  6. add1' [] _ _ = []
  7. add1' xs n 0 = xs
  8. add1' (x:xs) n c
  9. | x == n = x+1:(add1' xs n (c-1))
  10. | otherwise = x:add1' xs n c
  11.  
  12. -- Below are the test runs
  13. param = [1,4,1,5,1]
  14.  
  15. main :: IO ()
  16. main = do
  17. putStrLn . show $ param
  18. putStrLn . show $ add1 param 1 0
  19. putStrLn . show $ add1 param 1 2
  20. putStrLn . show $ add1 param 1 (-2)
Advertisement
Add Comment
Please, Sign In to add comment