Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- coalesce' :: [(String, Integer)] -> [(String, Integer)]
- coalesce' tups
- | myLength tups >= 2 = compress' (elementAt 0 (nehmen 2 tups) ) (elementAt 1 (nehmen 2 tups) ) ++ coalesce' (lassmaweg 2 tups)
- | otherwise = tups
- nehmen :: Integer -> [a] -> [a]
- nehmen n list
- | n <= 0 = []
- | myLength list <= n = []
- | otherwise = [head list] ++ nehmen (n-1) (tail list)
- lassmaweg :: Integer -> [a] -> [a]
- lassmaweg n list
- | n < 0 = []
- | myLength list <= n = []
- | n == 0 = list
- | otherwise = [] ++ lassmaweg (n-1) (tail list)
- elementAt :: Integer -> [a] -> a
- elementAt index list
- | index < 0 = head list
- | myLength list <= index = head list
- | index == 0 = head list
- | otherwise = elementAt (index - 1) (tail list)
- compress' :: (String,Integer) -> (String,Integer) -> [(String,Integer)]
- compress' a b
- | fst a == fst b = [(fst a, snd a + snd b)]
- | otherwise =[a,b]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement