Advertisement
bkayalibay

Untitled

Oct 31st, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. coalesce' :: [(String, Integer)] -> [(String, Integer)]
  2. coalesce' tups
  3.     | myLength tups >= 2 = compress' (elementAt 0 (nehmen 2 tups) ) (elementAt 1 (nehmen 2 tups) ) ++ coalesce' (lassmaweg 2 tups)
  4.     | otherwise = tups
  5.    
  6. nehmen :: Integer -> [a] -> [a]
  7. nehmen n list
  8.     | n <= 0 = []
  9.     | myLength list <= n = []
  10.     | otherwise = [head list] ++ nehmen (n-1) (tail list)
  11.    
  12. lassmaweg :: Integer -> [a] -> [a]
  13. lassmaweg n list
  14.     | n < 0 = []
  15.     | myLength list <= n = []
  16.     | n == 0 = list
  17.     | otherwise = [] ++ lassmaweg (n-1) (tail list)
  18.  
  19. elementAt :: Integer -> [a] -> a
  20. elementAt index list
  21.     | index < 0 = head list
  22.     | myLength list <= index = head list
  23.     | index == 0 = head list
  24.     | otherwise = elementAt (index - 1) (tail list)
  25.    
  26. compress' :: (String,Integer) -> (String,Integer) -> [(String,Integer)]
  27. compress' a b
  28.     | fst a == fst b = [(fst a, snd a + snd b)]
  29.     | otherwise =[a,b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement