<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>11</StartArguments>
+ <StartArguments>12</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day9.fs" />
<Compile Include="Day10.fs" />
<Compile Include="Day11.fs" />
+ <Compile Include="Day12.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
- <None Include="Data\day1.input">
+ <Content Include="Data\day1.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day2.input">
+ </Content>
+ <Content Include="Data\day2.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day4.input">
+ </Content>
+ <Content Include="Data\day4.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day5.input">
+ </Content>
+ <Content Include="Data\day5.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day6.input">
+ </Content>
+ <Content Include="Data\day6.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day7.input">
+ </Content>
+ <Content Include="Data\day7.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day8.input">
+ </Content>
+ <Content Include="Data\day8.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day9.input">
+ </Content>
+ <Content Include="Data\day9.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
- <None Include="Data\day11.input">
+ </Content>
+ <Content Include="Data\day11.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
- </None>
+ </Content>
+ <Content Include="Data\day12.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day12
+
+open System
+open System.Linq
+open System.Collections.Generic
+
+type Graph =
+ {
+ Name : string
+ Neighbors : List<Graph>
+ }
+
+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 f (input : (Graph * string[]) list) =
+ let toVisit = Dictionary<string, Graph> ()
+
+ for g, names 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')
+
+ let visited = List<Dictionary<string, Graph>> ()
+
+ let rec visit (g : Graph) (dic : Dictionary<string, Graph>) =
+ if dic.ContainsKey g.Name |> not then
+ toVisit.Remove g.Name |> ignore
+ dic.Add (g.Name, g)
+ for n in g.Neighbors do
+ visit n dic
+
+ while toVisit.Count > 0 do
+ let dic = Dictionary<string, Graph> ()
+ visited.Add dic
+ visit (toVisit.First().Value) dic
+
+ visited.First().Count, visited.Count
+
let part1, part2 = Day11.distanceInHex input
sprintf "part1 = %A, part2 = %A" part1 part2
+let day12 () =
+ let input = File.ReadAllLines "Data/day12.input" |> Day12.parseInput
+ let part1, part2 = Day12.f input
+ sprintf "part1 = %A, part2 = %A" part1 part2
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 9 -> day9 ()
| 10 -> day10 ()
| 11 -> day11 ()
+ | 12 -> day12 ()
| _ -> raise <| NotImplementedException ()
printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds