<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>14</StartArguments>
+ <StartArguments>15</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day13.fs" />
<Compile Include="Day14.fs" />
<Compile Include="Day14Compact.fs" />
+ <Compile Include="Day15.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="Data\day1.input">
<Content Include="Data\day13.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Data\day14.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ <Content Include="Data\day15.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day15
+
+let hash = Day10.knotHash2Encoding (fun i -> System.Convert.ToString(i, 2).PadLeft(8, '0'))
+
+let buildMatrix (input : string) =
+ let mat = Array2D.zeroCreate 128 128
+ for i = 0 to 127 do
+ input + "-" + (string i) |> hash |> Seq.iteri (fun j c -> mat.[i, j] <- int c - int '0')
+ mat
+
+let nbOfUsedSquares (input : string) =
+ let mutable i = 0
+ buildMatrix input |> Array2D.iter (fun b -> i <- i + b)
+ i
+
+let nbOfConnectedRegions (input : string) =
+ let m = buildMatrix input
+
+ let rec remove i j =
+ if i >= 0 && i < 128 && j >= 0 && j < 128 && m.[i, j] = 1 then
+ m.[i, j] <- 0
+ 1 + remove (i + 1) j * remove (i - 1) j * remove i (j + 1) * remove i (j - 1)
+ else
+ 0
+
+ [ for i in 0 .. 127 do for j in 0 .. 127 -> remove i j ] |> List.sum
\ No newline at end of file
sprintf "part1 = %A, part2 = %A" part1 part2
let day14 () =
- let part1 = Day14.nbOfUsedSquares "hwlqcszp"
- let part2 = Day14.nbOfConnectedRegions "hwlqcszp"
- sprintf "part1 = %A, part2 = %A" part1 part2
+ let input = File.ReadAllText "Data/day14.input"
+ sprintf "part1 = %A, part2 = %A" (Day14.nbOfUsedSquares input) (Day14.nbOfConnectedRegions input)
+
+let day15 () =
+ let input = File.ReadAllText "Data/day15.input"
+ sprintf "part1 = %A, part2 = %A" () ()
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
| 12 -> day12 ()
| 13 -> day13 ()
| 14 -> day14 ()
+ | 15 -> day15 ()
| _ -> raise <| NotImplementedException ()
printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds
--- /dev/null
+namespace AdventOfCode2017.Tests
+
+open Xunit
+open Xunit.Abstractions
+open Swensen.Unquote
+
+open AdventOfCode2017
+
+type ``Day15 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ ()
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ ()
\ No newline at end of file
<Compile Include="Day12 tests.fs" />
<Compile Include="Day13 tests.fs" />
<Compile Include="Day14 tests.fs" />
+ <Compile Include="Day15 tests.fs" />
<Content Include="packages.config" />
<Content Include="App.config" />
</ItemGroup>