+-- | Compute the longest common suffix of a [(Int, String)] list that
+-- | starts with a dot
+longestDomain :: [(Int, String)] -> String
+longestDomain [] = ""
+longestDomain ((_,x):xs) =
+ let
+ onlyStrings = snd $ unzip xs
+ in
+ foldr (\ suffix accu -> if all (isSuffixOf suffix) onlyStrings
+ then suffix
+ else accu)
+ "" $ filter (isPrefixOf ".") (tails x)
+
+-- | Remove tails from the (Int, String) lists
+stripSuffix :: String -> [(Int, String)] -> [(Int, String)]
+stripSuffix suffix lst =
+ let sflen = length suffix in
+ map (\ (key, name) -> (key, take ((length name) - sflen) name)) lst