let parseInput (lines : string[]) : Map<int, Set<int>> =
lines
- |> Array.fold (
- fun dic str ->
+ |> Array.map (
+ fun str ->
let l = str.Split ([| ' '; ',' |], StringSplitOptions.RemoveEmptyEntries)
- dic.Add (int l.[0], l.[2 .. l.Length - 1] |> Array.map int |> Set.ofArray)
- ) Map.empty
+ int l.[0], l.[2..] |> Array.map int |> Set.ofArray
+ ) |> Map.ofArray
let graphCount (g : Map<int, Set<int>>) =
let rec visit (current : int) (visited : Set<int>) : Set<int> =
[<Fact>]
let ``(Part1) From web page`` () =
- ()
+ let input =
+ [|
+ "0 <-> 2"
+ "1 <-> 1"
+ "2 <-> 0, 3, 4"
+ "3 <-> 2, 4"
+ "4 <-> 2, 3, 6"
+ "5 <-> 6"
+ "6 <-> 4, 5"
+ |]
+ Day12.parseInput input |> Day12.graphCount |> fst =! 6
[<Fact>]
let ``(Part2) From web page`` () =
- ()
\ No newline at end of file
+ let input =
+ [|
+ "0 <-> 2"
+ "1 <-> 1"
+ "2 <-> 0, 3, 4"
+ "3 <-> 2, 4"
+ "4 <-> 2, 3, 6"
+ "5 <-> 6"
+ "6 <-> 4, 5"
+ |]
+ Day12.parseInput input |> Day12.graphCount |> snd =! 2
\ No newline at end of file