module Exercise_7 where import Data.List import Data.Function import Data.Maybe {-WETT-} trancl :: Eq a => [(Integer, (a, a))] -> [(Integer, (a, a))] trancl xs = snd $ head $ dropWhile (uncurry (/=)) $ zip p $ tail p where f b = nubBy ((==) `on` snd) $ sortOn fst $ b ++ comp xs b p = iterate f xs comp :: Eq b => [(Integer, (a, b))] -> [(Integer, (b, c))] -> [(Integer, (a, c))] comp _abs bcs = concat [ [ (i + j, (fst e, snd e')) | (j, e') <- bcs, snd e == fst e' ] | (i, e) <- _abs ] {-MCCOMMENT Takes too long, but works in theory for the tests, felt that it was too cheeky of a solution, but hey, if you accept it, fine by me! trancl :: Eq a => [(Integer, (a, a))] -> [(Integer, (a, a))] trancl [] = [] trancl xs = last $ take 50 $ iterate f xs where f b = nubBy ((==) `on` snd) $ sortOn fst $ b ++ comp xs b comp :: Eq b => [(Integer, (a, b))] -> [(Integer, (b, c))] -> [(Integer, (a, c))] comp _abs bcs = concat [ [ (i + j, (fst e, snd e')) | (j, e') <- bcs, snd e == fst e' ] | (i, e) <- _abs ] -} {-TTEW-}