module Exercise_7 where import Data.Function import Data.List import Data.Text (splitOn, pack, unpack) import Data.Maybe {-WETT-} comp :: Eq b => [(Integer,(a,b))] -> [(Integer,(b,c))] -> [(Integer,(a,c))] comp [] _ = [] comp ((distx, (a,b)):xs) ys = map (\(disty, (_,d))-> (distx+disty, (a,d))) ys' ++ comp xs ys where ys' = filter ((==b).fst.snd) ys partitionSet :: Eq a => [(Integer,(a,a))]-> [[(Integer,(a,a))]] partitionSet [] = [] partitionSet set = part1 : partitionSet part2 where (part1, part2) = partition (on (==) snd $ head set) set trancl :: Eq a => [(Integer,(a,a))] -> [(Integer,(a,a))] trancl set = if length cache == length set then cache else trancl cache where cache = map (minimumBy (on compare fst)) . partitionSet $ comp set set ++ set {-TTEW-}