From: Greg Burri Date: Tue, 12 Dec 2017 05:42:49 +0000 (+0100) Subject: More efficient X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=ce55f2b39f58e803f04a782a7fe799ce58234f1d;p=advent_of_code_2017.git More efficient --- diff --git a/AdventOfCode2017/Day12.fs b/AdventOfCode2017/Day12.fs index 8d840f1..1f83f1d 100644 --- a/AdventOfCode2017/Day12.fs +++ b/AdventOfCode2017/Day12.fs @@ -20,13 +20,14 @@ let parseInput (lines : string[]) : (Graph * string[]) list = let graphCount (input : (Graph * string[]) list) = let toVisit = Dictionary () - for g, names in input do + for g, _ in input do toVisit.Add (g.Name, g) - for name in names do - for g', _ in input do - if g'.Name = name then - g'.Neighbors.Add (g) - g.Neighbors.Add (g') + + for g, neighbors in input do + for neighbor in neighbors do + let g' = toVisit.[neighbor] + g'.Neighbors.Add g + g.Neighbors.Add g' let visitedGroups = List> () diff --git a/AdventOfCode2017/Program.fs b/AdventOfCode2017/Program.fs index 9b1269a..933a60a 100644 --- a/AdventOfCode2017/Program.fs +++ b/AdventOfCode2017/Program.fs @@ -54,7 +54,7 @@ let day11 () = let day12 () = let input = File.ReadAllLines "Data/day12.input" |> Day12.parseInput - let part1, part2 = Day12.f input + let part1, part2 = Day12.graphCount input sprintf "part1 = %A, part2 = %A" part1 part2 let doDay (n : int) =