let parseInput (lines : string[]) : (Graph * string[]) list =
[
for line in lines do
- let a = line.Split ([| ' '; ',' |], StringSplitOptions.RemoveEmptyEntries)
- yield { Name = a.[0]; Neighbors = List<Graph> () }, a.[2 .. a.Length - 1]
+ let splitLine = line.Split ([| ' '; ',' |], StringSplitOptions.RemoveEmptyEntries)
+ yield { Name = splitLine.[0]; Neighbors = List<Graph> () }, splitLine.[2 .. splitLine.Length - 1]
]
-let f (input : (Graph * string[]) list) =
+let graphCount (input : (Graph * string[]) list) =
let toVisit = Dictionary<string, Graph> ()
for g, names in input do
g'.Neighbors.Add (g)
g.Neighbors.Add (g')
- let visited = List<Dictionary<string, Graph>> ()
+ let visitedGroups = List<Dictionary<string, Graph>> ()
let rec visit (g : Graph) (dic : Dictionary<string, Graph>) =
if dic.ContainsKey g.Name |> not then
while toVisit.Count > 0 do
let dic = Dictionary<string, Graph> ()
- visited.Add dic
+ visitedGroups.Add dic
visit (toVisit.First().Value) dic
- visited.First().Count, visited.Count
+ visitedGroups.First().Count, visitedGroups.Count