module Exercise_7 where import Data.Function (on) import Data.List (sortBy, nubBy) import Data.Ord (comparing) {-WETT-} trancl xs = nubBy ((==) `on` snd) . sortBy (comparing fst) . concatMap (uncurry $ dfs []) $ [ (0, fst $ snd x) | x <- xs ] where dfs path w a = concat [ dfs (a:path) (w + w') t | (w', (f, t)) <- xs, f == a, f `notElem` path ] ++ [ (w, (last path, a)) | not $ null path ] {-TTEW-}