Problem 80a Solution

graphToAdjList : Graph comparable -> AdjList comparable
graphToAdjList (nodes, edges) = 
    List.map (\n -> (n, (edgesOf n edges))) nodes


edgesOf : comparable -> List (comparable, comparable) -> List comparable
edgesOf n edges =
    let
        (xs, ys) = List.unzip
          <| List.filter (\(x, y) -> x == n || y == n) edges
    in
        List.sort 
            <| Set.toList
            <| Set.fromList
            <| List.filter (\x -> x /= n) 
            <| xs ++ ys

Back to problem

results matching ""

    No results matching ""