<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>12</StartArguments>
+ <StartArguments>13</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day10.fs" />
<Compile Include="Day11.fs" />
<Compile Include="Day12.fs" />
+ <Compile Include="Day13.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="Data\day1.input">
<Content Include="Data\day12.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Data\day13.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day13
+
+open System
+
+let parseInput (lines : string[]) =
+ lines
+ |> Array.map (
+ fun line ->
+ let values = line.Split ([| ':'; ' ' |], StringSplitOptions.RemoveEmptyEntries)
+ int values.[0], int values.[1]
+ )
+
+let severity (input : (int * int)[]) : int * int =
+ let severity (f : int -> int -> int) delay =
+ input |> Array.sumBy (fun (depth, range) -> if (depth + delay) % (2 * range - 2) = 0 then f depth range else 0)
+
+ severity (*) 0, Seq.initInfinite (fun i -> i, severity (+) i) |> Seq.pick (fun (i, s) -> if s = 0 then Some i else None)
\ No newline at end of file
let part1, part2 = Day12.graphCount input
sprintf "part1 = %A, part2 = %A" part1 part2
+let day13 () =
+ let input = File.ReadAllLines "Data/day13.input" |> Day13.parseInput
+ let part1, part2 = Day13.severity input
+ sprintf "part1 = %A, part2 = %A" part1 part2
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 10 -> day10 ()
| 11 -> day11 ()
| 12 -> day12 ()
+ | 13 -> day13 ()
| _ -> 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 ``Day13 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ let input =
+ [|
+ "0: 3"
+ "1: 2"
+ "4: 4"
+ "6: 4"
+ |]
+ Day13.severity (Day13.parseInput input) |> fst =! 24
+
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ let input =
+ [|
+ "0: 3"
+ "1: 2"
+ "4: 4"
+ "6: 4"
+ |]
+ Day13.severity (Day13.parseInput input) |> snd =! 10
\ No newline at end of file
<Compile Include="Day10 tests.fs" />
<Compile Include="Day11 tests.fs" />
<Compile Include="Day12 tests.fs" />
+ <Compile Include="Day13 tests.fs" />
<Content Include="packages.config" />
<Content Include="App.config" />
</ItemGroup>