tools/unitCycles.hs
changeset 4384 615a3e7bd850
parent 4382 935de6cd5ea3
equal deleted inserted replaced
4383:0a7158f26ffa 4384:615a3e7bd850
    23 
    23 
    24 myf :: [(String, [String])] -> String
    24 myf :: [(String, [String])] -> String
    25 myf d = unlines . map (findCycle . fst) $ d
    25 myf d = unlines . map (findCycle . fst) $ d
    26     where
    26     where
    27     findCycle :: String -> String
    27     findCycle :: String -> String
    28     findCycle searched = intercalate ", " $ fc searched [searched]
    28     findCycle searched = searched ++ ": " ++ (intercalate ", " $ fc searched [])
    29         where
    29         where
    30         fc :: String -> [String] -> [String]
    30         fc :: String -> [String] -> [String]
    31         fc curSearch visited = let uses = curSearch `lookup` d in if isNothing uses then [] else concatMap t $ fromJust uses
    31         fc curSearch visited = let uses = curSearch `lookup` d; res = dropWhile null . map t $ fromJust uses in if isNothing uses || null res then [] else head res
    32             where
    32             where
    33             t u =
    33             t u =
    34                 if u == searched then
    34                 if u == searched then
    35                     [u]
    35                     [u]
    36                     else
    36                     else